0

我很难通过添加服务参考添加服务来工作。我可以毫无问题地调用该服务,并得到回复(我可以在 Fiddler 中看到它):

<?xml version='1.0' encoding='UTF-8'?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <SOAP-ENV:Body>
    <executeResponse>
      <request_number>REQ0048172</request_number>
    </executeResponse>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

但是,我executeResponse在那里得到一个空值。Reference.cs 中的相关部分如下。

界面:

[System.ServiceModel.ServiceContractAttribute(Namespace="http://www.serviceprovider.com/service")]
public interface Soap {

    // CODEGEN: Generating message contract since the operation execute is neither RPC nor document wrapped.
    [System.ServiceModel.OperationContractAttribute(Action="http://www.serviceprovider.com/service/execute", ReplyAction="*")]
    [System.ServiceModel.XmlSerializerFormatAttribute(SupportFaults=true)]
    executeResponse1 execute(executeRequest request);

}

客户:

public partial class SoapClient : System.ServiceModel.ClientBase<Soap>, Soap {

    executeResponse1 Soap.execute(executeRequest request) {
        return base.Channel.execute(request);
    }

    public executeResponse execute(execute execute1) {
        executeRequest inValue = new executeRequest();
        inValue.execute = execute1;
        executeResponse1 retVal = ((Soap)(this)).execute(inValue);
        return retVal.executeResponse;
    }

}

执行响应1:

[System.ServiceModel.MessageContractAttribute(IsWrapped=false)]
public partial class executeResponse1 {

    [System.ServiceModel.MessageBodyMemberAttribute(Namespace="http://www.serviceprovider.com/service", Order=0)]
    public executeResponse executeResponse;

}

执行响应:

[System.SerializableAttribute()]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="http://www.serviceprovider.com/service")]
public partial class executeResponse : object, System.ComponentModel.INotifyPropertyChanged {

    [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=0)]
    public string request_number { get; set; }

}

我不确定如何从 SOAP 响应返回到解决此问题。任何建议,将不胜感激。

4

1 回答 1

1

根据这个:

命名空间="http://www.serviceprovider.com/service"

WCF 期望主体下的 SOAP 元素具有上述命名空间。但是它们是空的。如果您可以更改结果soap(即使只是通过模拟它暂时进行测试)尝试用以下内容替换body元素:

<SOAP-ENV:Body xmlns="http://www.serviceprovider.com/service">

否则尝试在代理代码中设置 Namespace="" (我不确定 WCF 是否允许它)。您还可以用一个空字符串替换 WSDL 中的这个名称空间,这在生成代理方面可能更健壮一些。

最后,如果这样做没有帮助,请基于此 WSDL(或直接在您的代理中拥有的数据协定)设置 WCF 服务,并查看它返回的soap 与实际服务返回的soap 有何不同。

于 2013-08-30T20:03:33.433 回答