Web服务命名空间问题

时间:2010-11-13 15:04:15

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

我有一个由Java客户端调用的ASP.NET Web服务。客户端发送SOAP消息作为输入,但问题是它永远不会到达我的webservice方法。我总是得到空输入。我使用了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()

1 个答案:

答案 0 :(得分: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