Web Services 如何将soap请求中的字符串数组发送到webservice

polhcujo  于 2022-11-15  发布在  其他
关注(0)|答案(2)|浏览(266)

我无法将请求发送到Web服务。
不接受字符串数组,并向我显示错误。
我想在soap请求中发送数组字符串,但显示错误。
我Web服务:

This XML file does not appear to have any style information associated with it. The document tree is shown below.
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:typens="urn:HostIranSmsWebService" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" name="HostIranSmsWebService" targetNamespace="urn:HostIranSmsWebService">
<types>
<xsd:schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:HostIranSmsWebService">
<xsd:complexType name="ArrayOfstring">
<xsd:complexContent>
<xsd:restriction base="soapenc:Array">
<xsd:attribute ref="soapenc:arrayType" wsdl:arrayType="xsd:string[]"/>
</xsd:restriction>
</xsd:complexContent>
</xsd:complexType>
<xsd:complexType name="ArrayOfint">
<xsd:complexContent>
<xsd:restriction base="soapenc:Array">
<xsd:attribute ref="soapenc:arrayType" wsdl:arrayType="xsd:int[]"/>
</xsd:restriction>
</xsd:complexContent>
</xsd:complexType>
<xsd:complexType name="AccountInfo">
<xsd:all>
<xsd:element name="numbers" type="typens:ArrayOfstring"/>
<xsd:element name="defaultNumber" type="xsd:string"/>
<xsd:element name="receiveUrl" type="xsd:string"/>
<xsd:element name="sent" type="xsd:int"/>
<xsd:element name="received" type="xsd:int"/>
<xsd:element name="credit" type="xsd:int"/>
<xsd:element name="remaining" type="xsd:int"/>
</xsd:all>
</xsd:complexType>
</xsd:schema>
</types>
<message name="send">
<part name="username" type="xsd:string"/>
<part name="password" type="xsd:string"/>
<part name="to" type="xsd:string"/>
<part name="msg" type="xsd:string"/>
<part name="from" type="xsd:string"/>
<part name="time" type="xsd:int"/>
</message>
<message name="sendResponse">
<part name="sendResponse" type="xsd:int"/>
</message>
<message name="sendToMany">
<part name="username" type="xsd:string"/>
<part name="password" type="xsd:string"/>
<part name="to" type="typens:ArrayOfstring"/>
<part name="msg" type="xsd:string"/>
<part name="from" type="xsd:string"/>
<part name="time" type="xsd:int"/>
</message>
<message name="sendToManyResponse">
<part name="sendToManyResponse" type="typens:ArrayOfint"/>
</message>
<message name="deliveryStatus">
<part name="username" type="xsd:string"/>
<part name="password" type="xsd:string"/>
<part name="recipientId" type="xsd:int"/>
</message>
<message name="deliveryStatusResponse">
<part name="deliveryStatusResponse" type="xsd:int"/>
</message>
<message name="verifyReceive">
<part name="username" type="xsd:string"/>
<part name="password" type="xsd:string"/>
<part name="ticket" type="xsd:string"/>
</message>
<message name="verifyReceiveResponse">
<part name="verifyReceiveResponse" type="xsd:boolean"/>
</message>
<message name="accountInfo">
<part name="username" type="xsd:string"/>
<part name="password" type="xsd:string"/>
</message>
<message name="accountInfoResponse">
<part name="accountInfoResponse" type="typens:AccountInfo"/>
</message>
<message name="changePassword">
<part name="username" type="xsd:string"/>
<part name="password" type="xsd:string"/>
<part name="newPassword" type="xsd:string"/>
</message>
<message name="changePasswordResponse">
<part name="changePasswordResponse" type="xsd:void"/>
</message>
<message name="changeTrafficRelay">
<part name="username" type="xsd:string"/>
<part name="password" type="xsd:string"/>
<part name="newURL" type="xsd:string"/>
</message>
<message name="changeTrafficRelayResponse">
<part name="changeTrafficRelayResponse" type="xsd:void"/>
</message>
<portType name="HostIranSmsWebServicePort">
<operation name="send">
<documentation>Send one SMS.</documentation>
<input message="typens:send"/>
<output message="typens:sendResponse"/>
</operation>
<operation name="sendToMany">
<documentation>Send one SMS to many.</documentation>
<input message="typens:sendToMany"/>
<output message="typens:sendToManyResponse"/>
</operation>
<operation name="deliveryStatus">
<documentation>Check SMS delivery status.</documentation>
<input message="typens:deliveryStatus"/>
<output message="typens:deliveryStatusResponse"/>
</operation>
<operation name="verifyReceive">
<documentation>Verify sms validity when you receive an sms</documentation>
<input message="typens:verifyReceive"/>
<output message="typens:verifyReceiveResponse"/>
</operation>
<operation name="accountInfo">
<documentation>Get account info.</documentation>
<input message="typens:accountInfo"/>
<output message="typens:accountInfoResponse"/>
</operation>
<operation name="changePassword">
<documentation>Change account password.</documentation>
<input message="typens:changePassword"/>
<output message="typens:changePasswordResponse"/>
</operation>
<operation name="changeTrafficRelay">
<documentation>Change traffic relay.</documentation>
<input message="typens:changeTrafficRelay"/>
<output message="typens:changeTrafficRelayResponse"/>
</operation>
</portType>
<binding name="HostIranSmsWebServiceBinding" type="typens:HostIranSmsWebServicePort">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="send">
<soap:operation soapAction="urn:HostIranSmsWebServiceAction"/>
<input>
<soap:body use="encoded" namespace="urn:HostIranSmsWebService" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output>
<soap:body use="encoded" namespace="urn:HostIranSmsWebService" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
<operation name="sendToMany">
<soap:operation soapAction="urn:HostIranSmsWebServiceAction"/>
<input>
<soap:body use="encoded" namespace="urn:HostIranSmsWebService" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output>
<soap:body use="encoded" namespace="urn:HostIranSmsWebService" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
<operation name="deliveryStatus">
<soap:operation soapAction="urn:HostIranSmsWebServiceAction"/>
<input>
<soap:body use="encoded" namespace="urn:HostIranSmsWebService" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output>
<soap:body use="encoded" namespace="urn:HostIranSmsWebService" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
<operation name="verifyReceive">
<soap:operation soapAction="urn:HostIranSmsWebServiceAction"/>
<input>
<soap:body use="encoded" namespace="urn:HostIranSmsWebService" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output>
<soap:body use="encoded" namespace="urn:HostIranSmsWebService" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
<operation name="accountInfo">
<soap:operation soapAction="urn:HostIranSmsWebServiceAction"/>
<input>
<soap:body use="encoded" namespace="urn:HostIranSmsWebService" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output>
<soap:body use="encoded" namespace="urn:HostIranSmsWebService" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
<operation name="changePassword">
<soap:operation soapAction="urn:HostIranSmsWebServiceAction"/>
<input>
<soap:body use="encoded" namespace="urn:HostIranSmsWebService" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output>
<soap:body use="encoded" namespace="urn:HostIranSmsWebService" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
<operation name="changeTrafficRelay">
<soap:operation soapAction="urn:HostIranSmsWebServiceAction"/>
<input>
<soap:body use="encoded" namespace="urn:HostIranSmsWebService" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output>
<soap:body use="encoded" namespace="urn:HostIranSmsWebService" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
</binding>
<service name="HostIranSmsWebService">
<port name="HostIranSmsWebServicePort" binding="typens:HostIranSmsWebServiceBinding">
<soap:address location="http://sms.hostiran.net/webservice/v1/index.php"/>
</port>
</service>
</definitions>

我代码:

public String sendToMany(String username,String password,Category to,String msg,String from,Long time){
    SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    soapEnvelope.implicitTypes = true;
    soapEnvelope.dotNet = true;
    SoapObject soapReq = new SoapObject("urn:HostIranSmsWebService","sendToMany");
    soapReq.addProperty("username",username);
    soapReq.addProperty("password",password);
    soapEnvelope.addMapping("urn:HostIranSmsWebService","to",new Category().getClass());

    soapReq.addProperty("to",to);

    soapReq.addProperty("msg",msg);
    soapReq.addProperty("from",from);
    soapReq.addProperty("time",time);

    soapEnvelope.setOutputSoapObject(soapReq);
    HttpTransportSE httpTransport = new HttpTransportSE(url);

    try{

            httpTransport.call("urn:HostIranSmsWebService/sendToMany", soapEnvelope);

    }catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}



public class Category extends Vector<String> implements KvmSerializable
{
    /**
     * 
     */
    private static final long serialVersionUID = -1166006770093411055L;

    @Override
    public Object getProperty(int arg0) {
            return this.get(arg0);
    }

    @Override
    public int getPropertyCount() {
            return this.size();
    }

    @Override
    public void getPropertyInfo(int arg0, Hashtable arg1, PropertyInfo arg2) {
            arg2.name = "string";
            arg2.type = PropertyInfo.STRING_CLASS;
    }

    @Override
    public void setProperty(int arg0, Object arg1) {
            this.add(arg1.toString());
    }
    }

我请求代码:

Category to =new Category();
to.add("1111111111");
to.add("2222222222");
to.add("3333333333");
String res = sendToMany("user1", "pass1", to, "hi", "",Long.valueOf(0));

Eclipse中错误:

11-14 16:19:51.317: D/msg(681): org.xmlpull.v1.XmlPullParserException: expected: END_TAG {http://schemas.xmlsoap.org/soap/envelope/}Body (position:END_TAG </{http://schemas.xmlsoap.org/soap/envelope/}SOAP-ENV:Fault>@2:199 in java.io.InputStreamReader@44c28540)

谁能帮帮我问题出在哪里?

d8tt03nd

d8tt03nd1#

请理解这一点“由于一些历史原因,到目前为止,SOAP编码只存在于非标准Web服务框架支持的SAOP编码中,包括Axis2、Metro和CXF。”这在本文http://ssagara.blogspot.com/2011/10/soap-encoding-and-axis2.html中有清楚的解释
但即使你想使用它,基本上你的请求应该看起来像这样匹配你的Web服务.

<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:HostIranSmsWebService" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
   <soapenv:Header/>
   <soapenv:Body>
      <urn:sendToMany soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
         <username xsi:type="xsd:string">?</username>
         <password xsi:type="xsd:string">?</password>
         <to xsi:type="urn:ArrayOfstring" soapenc:arrayType="xsd:string[]"/>
         <msg xsi:type="xsd:string">?</msg>
         <from xsi:type="xsd:string">?</from>
         <time xsi:type="xsd:int">?</time>
      </urn:sendToMany>
   </soapenv:Body>
</soapenv:Envelope>

阅读此博客,为您的项目生成一个工作客户端。http://ssagara.blogspot.com/2011/10/soap-encoding-and-axis2.html。正如它所描述的,您可以使用Axis2的wsdl来编写脚本,为该wsdl生成一个工作客户端。请仔细阅读此博客,并使用wsdl2java.sh -uri service.wsdl -d xmlbeans命令来获得一个工作客户端。
您可以使用本教程来获得进一步的想法。http://onjava.com/pub/a/onjava/excerpt/jsoap_5/index1.html?page=2

6tdlim6h

6tdlim6h2#

我可以使用以下代码向SOAP(WCF)终结点发送XML请求:* (张贴我的“确切”版本,以避免误译)*

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Body>
        <MyServiceAction xmlns="http://myservicehost.com/">
            <somestringparameter>aaaaaaaa-0b11-432e-bf14-d8bb5e52e56a</somestringparameter>
            <anotherstring>dont care</anotherstring>
            <thisisanarray arrayType="string[]"><item type="string">OMS.PartnerService</item></thisisanarray>
        </MyServiceAction >
    </soap:Body>
</soap:Envelope>

Map至(C#)方法:

[OperationContract(Name = "MyServiceAction")]
bool MyServiceAction(string somestringparameter, string anotherstring, string[] thisisanarray) { ... }

在我的例子中,除了soap envelope(<soap:Envelop xmlns:soap...>)和Action的名称空间(<MyServiceAction xmlns=...>)之外,我不需要指定名称空间。我看到过其他为属性值string[]string声明特定名称空间的示例,但我不需要它们。
但是,从Eclipse错误中听起来,XML生成不正确?是否必须手动关闭一个元素?

相关问题