c# - 如何在 asmx Web 服务(wsdl)中操作端口类型?

标签 c# web-services binding wsdl

我有一个 asmx Web 服务。在我的 wsdl 中,我猜测默认生成的端口类型和绑定(bind)名称。我想要的是更改这些名称。我该怎么做?它与配置文件有关还是只有 c# 代码可以处理这个问题。你建议用什么方式让 wsdl 像下面这样。 感谢回复!

我的wsdl:

<wsdl:message name="sendDocumentSoap12In">
<wsdl:part name="document" element="tns:documentRequest"/>
</wsdl:message>
<wsdl:message name="sendDocumentSoap12Out">
<wsdl:part name="sendDocumentResult" element="tns:documentResponse"/>
</wsdl:message>

<wsdl:portType name="EFaturaSoap12">
<wsdl:operation name="sendDocument">
<wsdl:input message="tns:sendDocumentSoap12In"/>
<wsdl:output message="tns:sendDocumentSoap12Out"/>
</wsdl:operation>
</wsdl:portType>

<wsdl:binding name="EFaturaSoap12" type="tns:EFaturaSoap12">
<soap12:binding transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="sendDocument">
<soap12:operation soapAction="sendDocument" style="document"/>
<wsdl:input>
<soap12:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap12:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>

我想要的wsdl:

<wsdl:message name="sendDocument">
<wsdl:part element="tns:documentRequest" name="document"></wsdl:part>
</wsdl:message>
<wsdl:message name="sendDocumentResponse">
<wsdl:part element="tns:documentResponse" name="sendDocumentReturn"></wsdl:part>
</wsdl:message>

<wsdl:portType name="EFaturaPortType">
<wsdl:operation name="sendDocument">
<wsdl:input message="tns:sendDocument" name="sendDocument"></wsdl:input>
<wsdl:output message="tns:sendDocumentResponse" name="sendDocumentResponse"></wsdl:output>
<wsdl:fault message="tns:EFaturaFaultMessage" name="EFaturaFaultMessage"></wsdl:fault>
</wsdl:operation>
</wsdl:portType>

<wsdl:binding name="EFaturaSoapBinding" type="tns:EFaturaPortType">
<soap12:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="sendDocument">
<soap12:operation soapAction="sendDocument" style="document"/>
<wsdl:input name="sendDocument">
<soap12:body use="literal"/>
</wsdl:input>
<wsdl:output name="sendDocumentResponse">
<soap12:body use="literal"/>
</wsdl:output>
<wsdl:fault name="EFaturaFaultMessage">
<soap12:fault name="EFaturaFaultMessage" use="literal"/>
</wsdl:fault>
</wsdl:operation>
</wsdl:binding>

最佳答案

您可以说,WSDL 是您的配置文件。您可以像上面那样手动但要小心地更改它。您需要检查所有引用以更改 wsdl 中的值。像上面一样,您还需要使用新编辑的绑定(bind)名称来编辑服务标签。

任何 web 服务实现,以任何语言,都可以让您对这些名称进行有限控制。您可以在一定范围内控制这些名称。

类似于 jax-ws(用于 XML 网络服务的 JAVA API)。您可以根据您的方法或接口(interface)名称定义您的操作名称,端口类型取决于您的类名。通常在生成 wsdl 输入消息:MethodNameRequest 和输出消息:MethodNameResponse 时生成。我希望 C# 也能为您提供类似的实现。

通常在wsdl中,

• portType 元素可以比作传统编程语言中的函数库(或模块或类)。

• 操作元素可以比作传统编程语言中的方法。

• 消息元素定义操作或方法(输入/输出)的数据元素。

如果您想使用 wsdl 频繁地进行这些更改,您可以编写一个 DOM 解析器来生成根据您的要求进行更改的 wsdl。

关于c# - 如何在 asmx Web 服务(wsdl)中操作端口类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20758581/

相关文章:

ios - iOS从服务器内部获取数据以进行循环

使用 JAX-WS 将 Java 方法公开为 Web 服务

java - RESTful Web 服务加载 MYSQL 文件中的数据

java - 将服务绑定(bind)放在 onStart() 处是否不好?

c# - 绑定(bind)到 DevExpress StockSeries2D 图表

wcf - WCF 中的大请求问题

c# - 如何检查 JsonObject 是否为空值(windows.data.json)

c# - 对 Json 响应感到沮丧

c# - 从 Excel 文档中的代码隐藏访问 ActiveX 或表单对象(文本框)

c# - 计算csv文件中特定数字的数量