我正在创建.ASMX端点,以便第三方可以向我发送肥皂请求。第三方示例看起来像这样:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tns="http://catmanager.com/schemas/catmanager/v8.8.2/notify">
<soapenv:Header/>
<soapenv:Body>
<tns:notifyCatExtendedStatusChange xmlns:tns="http://catmanager.com/schemas/catmanager/v8.8.0/notify">
<CatJob>
<not:CatCode>FTC</not:CatCode>
<not:ClientStatus>URGENT</not:ClientStatus>
</CatJob>
</not:notifyCatExtendedStatusChange>
</soapenv:Body>
</soapenv:Envelope>
当我使用服务中的WSDL创建一个SOAPUI项目时,我的XML期望这一点:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:not="http://catmanager.com/schemas/catmanager/v8.8.2/notify">
<soapenv:Header/>
<soapenv:Body>
<not:notifyCatExtendedStatusChange>
<CatJob>
<not:CatCode>Bernard</not:CatCode>
<not:ClientStatus>NOT URGENT</not:ClientStatus>
</CatJob>
</not:notifyCatExtendedStatusChange>
</soapenv:Body>
</soapenv:Envelope>
我需要我的服务来接受 tns 而不是而不是。
我认为我需要强制前缀,但是我无法弄清楚如何做到这一点。我找到了这个链接,看起来非常复杂,但是如果没有更容易的方法,我将接下来尝试:http://benscoderepo.blogspot.co.uk/2014/12/adding-soap-prefix-to-asmx-service.html
这是我的ASMX代码:
using System.ComponentModel;
using System.Web.Services;
using System.Web.Services.Description;
using System.Web.Services.Protocols;
using System.Xml.Serialization;
namespace CatApp
{
[WebService(Namespace = "http://catmanager.com/schemas/catmanager/v8.8.2/notify")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ToolboxItem(false)]
public class CatService : System.Web.Services.WebService
{
[WebMethod]
[SoapRpcMethod("urn:notifyCatExtendedStatusChange",RequestNamespace = "http://catmanager.com/schemas/catmanager/v8.8.2/notify", ResponseNamespace = "http://catmanager.com/schemas/catmanager/v8.8.2/notify", Use = SoapBindingUse.Literal)]
[return: XmlElement("UpdateCatExtendedStatusResponse")]
public string notifyCatExtendedStatusChange(catJob CatJob)
{
return CatJob.ClientStatus;
}
}
public class catJob
{
public string CatCode { get; set; }
public string ClientStatus { get; set; }
}
public partial class updateCatExtendedStatusResponse
{
private int idField;
private bool statusUpdatedField;
[XmlElementAttribute(Form = global::System.Xml.Schema.XmlSchemaForm.Unqualified)]
public int Id
{
get
{
return this.idField;
}
set
{
this.idField = value;
}
}
[XmlElementAttribute(Form = global::System.Xml.Schema.XmlSchemaForm.Unqualified)]
public bool StatusUpdated
{
get
{
return this.statusUpdatedField;
}
set
{
this.statusUpdatedField = value;
}
}
}
}
我更改了
Use = SoapBindingUse.Literal
to
Use = SoapBindingUse.Default
它开始使用第三方示例。我将其切换回文字,它仍然有效。我很神秘,但我很高兴一切都开始工作。
问题不是前缀。问题是第三方意外发送了错误的名称空间:
http://catmanager.com/schemas/catmanager/v8.8。