1

我无法将我的请求发送到网络服务。

字符串数组不接受并向我显示错误。

我想在肥皂请求中发送数组字符串,但向我显示错误。

我的网络服务:

    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));

日食中的错误:

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) 

有人可以帮我解决问题吗?

4

2 回答 2

0

请理解这一点“到目前为止,SOAP 编码仅由于某些历史原因而存在,标准 Web 服务框架不支持包括 Axis2、Metro 和 CXF 在内的 SAOP 编码。” 这在这篇文章中得到了清晰的解释,http://ssagara.blogspot.com/2011/10/soap-encoding-and-axis2.html

但即使你想使用它,基本上你的请求应该看起来像这样以匹配你的网络服务。

<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

于 2012-11-16T02:50:19.067 回答
0

我可以使用以下内容向 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>

对应一个(C#)方法:

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

在我的例子中,我不需要指定肥皂信封 ( <soap:Envelop xmlns:soap...>) 和我的 Action 的命名空间 ( <MyServiceAction xmlns=...>) 之外的命名空间。string[]我已经看到了为属性值和声明特定命名空间的其他示例string,但我不需要它们。

但是从您的 Eclipse 错误中听起来您的 XML 生成不正确?你必须手动关闭一个元素吗?

于 2013-07-10T14:36:52.643 回答