由于我无法控制的Web服务的要求,我需要更改我的ns前缀来自默认的" s"和" h"。服务提供商已为我的服务引用提供了.wsdl文件,但是,它们似乎没有用于元数据交换的联机wsdl。我已经通过电子邮件发送了他们,他们确认前缀必须是特定的值(他们的对与否是正确的,我必须做到这一点)。
有人可以告诉我更改这些值的最简单方法吗?我可以在Reference.cs中修改一些内容吗?我是否必须在我的请求中实现某种消息格式化逻辑,以便在发出请求之前更改值?
XML中的每个元素都必须具有特定值的前缀(总共2个值),否则WS将不接受请求并仅在响应中返回HTML。当我将Fiddler中捕获的请求复制到SOAP UI并将前缀更新为所需内容时,从Soap UI执行时请求正常。我对c#VS 2017开发平台这个看似简单的问题没有找到任何简单的解决方案。
另外值得注意的是,当我将.wsdl文件加载到Soap UI中时,Soap UI会在我的c#app中生成所需的正确所需前缀的所有ws操作和请求。 Soap UI如何知道在请求中生成的确切前缀?
我需要修改一下:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
<h:FooListHeader xmlns:h="http://foo.foo.com/Hello" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<h:FooList>
<h:FooStatement>
<h:Title>Foo</h:Title>
<h:Value>123</h:Value>
</h:FooStatement>
</h:FooList>
</h:FooListHeader>
</s:Header>
<s:Body>
<GetFooRequestType xmlns="http://foo.foo.com/Hello">
<MessageRequest xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<ConFooRequest/>
</MessageRequest>
</GetFooRequestType>
</s:Body>
</s:Envelope>
对于这样的事情:
<soapenv:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:foo="http://foo.foo.com/Hello">
<soapenv:Header>
<foo:FooListHeader xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<foo:FooList>
<foo:FooStatement>
<foo:Title>Foo</foo:Title>
<foo:Value>123</foo:Value>
</foo:FooStatement>
</foo:FooList>
</foo:FooListHeader>
</soapenv:Header>
<soapenv:Body>
<foo:GetFooRequestType xmlns="http://foo.foo.com/Hello">
<foo:MessageRequest xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<foo:ConFooRequest/>
</foo:MessageRequest>
</foo:GetFooRequestType>
</soapenv:Body>
</soapenv:Envelope>
示例c#代码:
public GetYaddaYaddaResponseType CheckConnection()
{
Yadda client = new Yadda();
var msgRequest = new GetYaddaYaddaResponseType { ConnectionConfirmationRequest = new ConfirmConnectRequestType() };
List<Statement> statementList = new List<Statement>
{
new Statement { Name = "Yo", Value = "123" },
new Statement { Name = "Hey", Value = "123" },
};
var header = new StatementHeader
{
StatementList = statementList.ToArray()
};
var response = client.GetYaddaYaddaMessage(ref header, msgRequest);
return response;
}