[英]Migrating a WCF application from SOAP to REST
我有一個 WCF 應用程序當前正在 SOAP 配置中運行,我需要將其轉換為 REST。
理論上,我可以正常工作,但是當我使用 curl 調用 RST API 時,出現錯誤:
curl -v http://localhost:8853/ClearCore/SecMyPermissions
由於 EndpointDispatcher 上的 ContractFilter 不匹配,無法在接收方處理帶有 Action“”的消息。 這可能是因為合同不匹配(發送方和接收方之間的操作不匹配)或發送方和接收方之間的綁定/安全不匹配。 檢查發送方和接收方是否具有相同的合同和相同的綁定(包括安全要求,例如消息、傳輸、無)。
它說“無法處理操作”的那一點向我暗示我的配置錯誤,以至於它無法識別正在傳入的 function 名稱。
[ServiceContract]
[Guid("5098109F-DB33-44e6-87B8-1929C879515B")]
public interface class IClearCoreSoap
{
[OperationContract]
[FaultContract(Exception::typeid)]
virtual List<System::String^>^ SecMyPermissions();
}
[ServiceBehavior(IncludeExceptionDetailInFaults = true, ConcurrencyMode = ConcurrencyMode::Multiple,
InstanceContextMode=InstanceContextMode::PerCall,
AddressFilterMode = AddressFilterMode::Any)]
public ref class ClearCoreSoap : IClearCoreSoap
{
public:
virtual List<System::String^>^ SecMyPermissions();
}
System::ServiceModel::ServiceHost^ pServiceHost = gcnew System::ServiceModel::ServiceHost(ClearCoreSoap::typeid);
pServiceHost->Open();
<configuration>
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding maxReceivedMessageSize="1000000" name="NoSecurity">
<readerQuotas maxDepth="1000000" maxStringContentLength="65535"/>
</binding>
<binding maxBufferSize="1000000" maxReceivedMessageSize="1000000" name="BasicSecurity">
<readerQuotas maxDepth="1000000" maxStringContentLength="65535"/>
<security mode="Transport"/>
</binding>
</webHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="webHttpBehavior" name="soapcon.ClearCoreSoap">
<endpoint address="http://localhost:8853/ClearCore" binding="webHttpBinding" bindingConfiguration="NoSecurity" contract="soapcon.IClearCoreSoap" name="ClearCore"/>
<host>
<baseAddresses>
<add baseAddress="http://localhost:8853/ClearCore"/>
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="webHttpBehavior">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="false"/>
<serviceCredentials type="System.ServiceModel.Description.ServiceCredentials">
<clientCertificate>
<authentication certificateValidationMode="None"/>
</clientCertificate>
<userNameAuthentication customUserNamePasswordValidatorType="soapcon.ADRetry_Validator, server_console_d" userNamePasswordValidationMode="Custom"/>
</serviceCredentials>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="webHttpBehavior">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
“EndpointDispatcher 上的 ContractFilter 不匹配”意味着接收方無法處理消息,因為它與接收方為接收消息的端點配置的任何合同不匹配。
這可能是因為:
你可以參考這個線程來解決問題。
根據您提供的代碼,您可以嘗試以下操作:
<endpoint address="http://localhost:8853/ClearCore" binding="webHttpBinding" bindingConfiguration="NoSecurity" contract="soapcon.IClearCoreSoap" name="ClearCore"/>
<endpoint address />
標簽中添加行為配置
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.