【问题标题】:Webservice Namespace problemWeb服务命名空间问题
【发布时间】:2011-05-09 13:24:33
【问题描述】:

我有一个由 Java 客户端调用的 ASP.NET 网络服务。客户端发送一个 SOAP 消息作为输入,但问题是它永远不会到达我的 web 服务方法。我总是得到空输入。我使用 TraceListener 并看到了可能导致问题的警告:

在此上下文中不需要该元素:... 预期元素:http://client.ns.url/:ListenerInput

这是客户端发送的内容:

<?xml version="1.0" encoding="utf-8"?>
<S:Envelope xmlns:S = "http://schemas.xmlsoap.org/soap/envelope/">
    <S:Body>
        <ns2:Listener xmlns:ns2 = "http://client.ns.url/">
            <ListenerInput>
                <errorCode>0</errorCode>
                <errorDescription>Success</errorDescription>
                <firstPrice xsi:nil = "true" xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"/>
            </ListenerInput>
        </ns2:Listener>
    </S:Body>
</S:Envelope>

这是我的网络方法:

[System.Web.Services.WebServiceAttribute(Namespace = "http://client.ns.url/")]
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.42")]
[System.Web.Services.WebServiceBindingAttribute(Name = "ListenerWebServicePortSoapBinding", Namespace = "http://client.ns.url/")]
public partial class ListenerService : System.Web.Services.WebService
{

    [System.Web.Services.WebMethodAttribute()]
    [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://client.different.url/services/action/ListenerService/Listener", RequestElementName = "Listener", RequestNamespace = "http://client.ns.url/", ResponseNamespace = "http://client.ns.url/", Use = System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle = System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
    [return: System.Xml.Serialization.XmlElementAttribute("return")] 
    public ListenerResponse Listener([System.Xml.Serialization.XmlElementAttribute("ListenerInput")]ListenerInput listenerInput)
    {
..

这是输入类:

[System.Xml.Serialization.XmlTypeAttribute(Namespace = "http://client.ns.url")]
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.42")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
public partial class ListenerInput
{
    public int errorCode;
    public string errorDescription;
    public float? firstPrice;
}

我应该怎么做才能解决这个问题?这是一些跟踪日志:

Calling IHttpHandler.ProcessRequest
    Caller: System.Web.Services.Protocols.SyncSessionlessHandler#47754503::ProcessRequest()
    Request Host Address: xxx
    Request Url: [POST] http:/my.website/Listener.asmx
..
Calling XmlSerializer [Read Request]
    Method: Microsoft.Xml.Serialization.GeneratedAssembly.ArrayOfObjectSerializer#53218107::Deserialize(System.Web.Services.Protocols.SoapServerProtocol+SoapEnvelopeReader#4153573=.., (null))
    Caller: System.Web.Services.Protocols.SoapServerProtocol#51389704::ReadParameters()
...
The element was not expected in this context: <ListenerInput>..</ListenerInput>. Expected elements: http://client.ns.url/:ListenerInput.
...
Return from XmlSerializer [Read Request]
    Caller: System.Web.Services.Protocols.SoapServerProtocol#51389704::ReadParameters()
...
 Calling ListenerResponse Listener(ListenerInput)
    Method: ListenerService#64693151::Listener((null))
    Caller: System.Web.Services.Protocols.SyncSessionlessHandler#47754503::Invoke()

【问题讨论】:

    标签: web-services .net-3.5 soap namespaces


    【解决方案1】:

    解决了这个问题。当我应该使用自己的命名空间地址时,我使用的是客户端的命名空间地址。改变了这个:

    [System.Web.Services.WebServiceBindingAttribute(Name = "ListenerWebServicePortSoapBinding", Namespace = "http://client.ns.url/")]
    public partial class ListenerService : System.Web.Services.WebService
    

    到这里:

    [System.Web.Services.WebServiceBindingAttribute(Name = "ListenerWebServicePortSoapBinding", Namespace = "http://my.ns.url/")]
    public partial class ListenerService : System.Web.Services.WebService
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-09-07
      • 1970-01-01
      • 2016-06-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多