Lui*_*cia 12 c# rest wcf soap postman
我正在尝试使用 WCF 端点调用服务。WCF 服务托管在 Windows 服务上,
这是配置。
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.diagnostics>
<sources>
<source name="System.ServiceModel" propagateActivity="true" switchValue="All">
<listeners>
<add name="xmlTraceListener" />
</listeners>
</source>
<source name="System.ServiceModel.MessageLogging" switchValue="All">
<listeners>
<add name="xmlTraceListener" />
</listeners>
</source>
</sources>
<sharedListeners>
<add name="xmlTraceListener"
type="System.Diagnostics.XmlWriterTraceListener"
initializeData="C:\logwcf\Service.svclog" />
</sharedListeners>
</system.diagnostics>
<system.web>
<httpRuntime executionTimeout="90" />
</system.web>
<startup useLegacyV2RuntimeActivationPolicy="True">
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1" />
</startup>
<system.serviceModel>
<diagnostics>
<messageLogging logEntireMessage="true"
logMalformedMessages="true"
logMessagesAtServiceLevel="true"
logMessagesAtTransportLevel="true">
<filters>
<clear/>
</filters>
</messageLogging>
</diagnostics>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_Hostware" closeTimeout="00:10:30" openTimeout="00:10:30" receiveTimeout="00:10:30" sendTimeout="00:10:30" allowCookies="false" bypassProxyOnLocal="false" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" textEncoding="utf-8" transferMode="Streamed" useDefaultWebProxy="true" messageEncoding="Text">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
<services>
<service name="xx.ServicioDistribucion.AnalisisDatos.Servicios.CuentasCobrar" behaviorConfiguration="behaviorDistribucion">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_Hostware" contract="xx.ServicioDistribucion.AnalisisDatos.Interfaces.ICuentasCobrar">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
<host>
<baseAddresses>
<add baseAddress="http://xx.143.46.82:8733/xx.ServicioDistribucion.AnalisisDatos.Servicios.CuentasCobrar/"/>
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="behaviorDistribucion">
<serviceThrottling maxConcurrentSessions="10000"/>
<!-- To avoid disclosing metadata information,
set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="True"/>
<!-- To receive exception details in faults for debugging purposes,
set the value below to true. Set to false before deployment
to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="true"/>
<!--<dataContractSerializer maxItemsInObjectGraph="2147483646"/>-->
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https"/>
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
</system.serviceModel>
</configuration>
Run Code Online (Sandbox Code Playgroud)
我们正在尝试使用 POSTMAN 调用服务,如下所示:
这是原始身体:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">
<soapenv:Header/>
<soapenv:Body>
<tem:ProcesarListaCuentasCobrarCIA100/>
</soapenv:Body>
</soapenv:Envelope>
Run Code Online (Sandbox Code Playgroud)
但是,我们得到了这个回应
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<s:Fault>
<faultcode xmlns:a="http://schemas.microsoft.com/ws/2005/05/addressing/none">a:DestinationUnreachable</faultcode>
<faultstring xml:lang="es-CO">The message with To 'http://xx.143.46.82:8733/xxServicioDistribucion.AnalisisDatos.Servicios.CuentasCobrar/ProcesarListaCuentasCobrarCIA100/' cannot be processed at the receiver, due to an AddressFilter mismatch at the EndpointDispatcher. Check that the sender and receiver's EndpointAddresses agree.</faultstring>
</s:Fault>
</s:Body>
</s:Envelope>
Run Code Online (Sandbox Code Playgroud)
内容类型为 text/xml。
我们正在尝试使用 POST
фым*_*нок 16
运行您的 WCF。例如https://docs.microsoft.com/en-us/dotnet/framework/wcf/getting-started-tutorial


标题 -
内容类型:文本/xml
SOAPAction: http://Microsoft.ServiceModel.Samples/ICalculator/Add
4. 从 WCF 测试客户端添加正文。对我来说身体是
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<Add xmlns="http://Microsoft.ServiceModel.Samples">
<n1>1</n1>
<n2>1</n2>
</Add>
</s:Body>
</s:Envelope>
Run Code Online (Sandbox Code Playgroud)
IIRC 当您对 WCF 服务器进行 SOAP 调用时,除了正文内容之外,还必须设置 HTTP 标头。
我的旧 SOAP 调用具有以下形式的标头:
SOAPAction: http://domain/EndPoint
Run Code Online (Sandbox Code Playgroud)
您可能需要检查一下。如果您有工作客户端,请使用 Fiddler 捕获流量。此外,我将内容类型设置为“text/xml; charset=utf-8”,我似乎记得有些服务器对 POST 上的内容类型很挑剔。
我发现在 Postman 中进行 WCF 调用的最简单方法如下......
1.) 打开 Fiddler 并在本地调试 WCF 项目,Visual Studio WCF 测试客户端将打开。
2.) 在 WCF 测试客户端中调用您的服务方法以获取响应。
3.) 单击 Fiddler 中的请求。
4.) 单击 fiddler 中的“RAW”选项卡查看请求,然后复制请求标头中的信封标签。
它应该看起来像
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body><YourMethodName xmlns="http://yourserver.com/serviceName/v1.0"/></s:Body></s:Envelope>
Run Code Online (Sandbox Code Playgroud)
5.) 在 Postman 中创建一个新请求,然后打开 BODY 选项卡,选择“raw”单选按钮。
6.) 将内容类型下拉菜单设置为“XML”。
7.) 将上面的信封标签粘贴到 Postman 的 BODY 字段中。
8.) 将 Postman 中的 URL 设置为 Fiddler 中发出的任何请求,它将是 Fiddler 中请求的第一行,例如http://server/yourservice.svc
9.) 将Postman中的请求类型更改为POST
10.) 切换到 Postman 中的 HEADERS 选项卡,添加一个 CONTENT-TYPE 标头,值为“text/html”
11.) 在 Fiddler 请求中,您将看到一个 SOAPAction 标头,复制此标头中的 URL
12.) 在 Postman 的 HEADERS 选项卡中,添加“SOAPAction”标头,并将 URL 标头粘贴到该值中。
13.) 运行您的服务!
奖金
如果要从 Postman 调用远程 WCF 服务(无法在本地运行),请调试本地项目,以便打开 WCF 测试客户端。
1.) 右键单击 WCF 测试客户端中的“我的服务项目”树节点,然后单击“添加服务”。
2.) 输入您的服务 URL
3.) 像执行本地服务一样调用它的方法,然后按照上述步骤在 Fiddler 中跟踪并添加到 Postman。
| 归档时间: |
|
| 查看次数: |
49911 次 |
| 最近记录: |