【问题标题】:how to send string array in soap request to webservice如何将soap请求中的字符串数组发送到webservice
【发布时间】:2012-11-14 13:08:09
【问题描述】:

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

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

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

我的网络服务:

    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) 

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

【问题讨论】:

  • 您使用的客户端代码是什么?基本上,您的请求应该如下所示,以匹配您的网络服务。

标签: android web-services wsdl ksoap2


【解决方案1】:

请理解“到目前为止,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

【讨论】:

  • 如何在我的网络服务中传递这部分? sendToMany 消息:
  • 谢谢大家,但仍然没有我的答案...请帮助我...我需要这个答案...:(
  • 为什么这对您没有帮助?您想要向 WSDL 中描述的 Web 服务发送请求吗?因此,您可以通过上述命令获取 Java 客户端并使用它。你怎么了?
【解决方案2】:

我能够使用以下内容向 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) { ... }

就我而言,我不需要指定肥皂信封 (&lt;soap:Envelop xmlns:soap...&gt;) 和我的 Action 的命名空间 (&lt;MyServiceAction xmlns=...&gt;) 之外的命名空间。我见过其他示例为属性值 string[]string 声明了特定的命名空间,但我不需要它们。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-08-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多