NET 4.5的WCF SOAP服务 [英] WCF SOAP Service with .net 4.5

查看:59
本文介绍了NET 4.5的WCF SOAP服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个非常简单的肥皂服务,并且运行良好,但是我想为肥皂信封添加一些属性我的代码"

I have created very simple soap service and it is working good but I want to add some attributes to the soap envelop My Code

界面

namespace SOAPService
{
[ServiceContract]
public interface IService
{
[OperationContract]
double AddNumbers(double number1, double number2);
}
}

svc代码

svc code

namespace SOAPService
{

public class Service : IService
{
public double AddNumbers(double number1, double number2)
{
double result = number1 + number2;
return result;
}
}
}

在SOAPUI中打开请求时,它看起来像

When open request in SOAPUI It looks like

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">
<soapenv:Header/>
<soapenv:Body>
<tem:AddNumbers>
<!--Optional:-->
<tem:number1>1</tem:number1>
<!--Optional:-->
<tem:number2>1</tem:number2>
</tem:AddNumbers>
</soapenv:Body>
</soapenv:Envelope>

但是我一直在寻找这样的输出

But I was looking output like this

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" xmlns:xsd="http://www.w3.org/1999/XMLScheme>
<soapenv:Header/>
<soapenv:Body>
<tem:AddNumbers>
<!--Optional:-->
<tem:number1>1</tem:number1>
<!--Optional:-->
<tem:number2>1</tem:number2>
</tem:AddNumbers>
</soapenv:Body>
</soapenv:Envelope>

如何添加那些xmlns:xsi和xmlns:xsd属性

How can I add those xmlns:xsi and xmlns:xsd attributes

推荐答案

在我的选择中,您的预期结果不是有效的SOAP请求

In my option, your expected result is not a valid SOAP request.

  1.       "SOAP-ENV:Envelope"未关闭
  2.   ;     如果使用"SOAP-ENV:信封",则需要在子节点中使用
  1.        "SOAP-ENV:Envelope" is not closed
  2.        If you use "SOAP-ENV:Envelope", you need to use it in sub nodes

以下是带有xmlins的有效SOAP请求.

Below is a valid SOAP request with xmlins.

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" xmlns:xsd="http://www.w3.org/1999/XMLScheme">
   <SOAP-ENV:Header/>
   <SOAP-ENV:Body>
      <tem:AddNumbers>
         <!--Optional:-->
         <tem:number1>1</tem:number1>
         <!--Optional:-->
         <tem:number2>2</tem:number2>
      </tem:AddNumbers>
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

您如何发送上述请求?该请求取决于客户端如何生成它.为了在WCF客户端中使用此请求,您需要在WCF客户端中更改消息,而这不会反映在SOAPUI中.

How do you want to send above request? The request is depended on how client generated it. For consuming this request in WCF Client side, you need to change message in WCF client side, and this would not be reflected in SOAPUI.

要在WCF客户端中更改消息,建议您参考以下链接.

For changing message in WCF client, I suggest you refer below link.

#更改WCF服务的XML响应中的前缀

# Changing prefixes in XML responses for WCF services

https://blogs.msdn.microsoft.com/carlosfigueira/2010/06/12/changing-prefixes-in-xml-responses-for-wcf-services/

如果要使用SOAPUI进行发送,则需要手动发送上述请求,恐怕没有配置可以在SOAPUI工具中进行设置,也不需要在WCF服务端进行任何更改.

If you want to send it with SOAPUI, you need to manually send above request, I am afraid there is no configuration to set this in SOAPUI tool, there is no need to change anything in WCF Service side.


这篇关于NET 4.5的WCF SOAP服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆