[英]Cannot call WCF WebService from DLL
我正在嘗試從在我的CAD軟件中運行的dll中調用WCF Web服務。 我不能使它正常工作。
當我嘗試建立代理時,出現以下錯誤:
在ServiceModel客戶端配置部分中找不到名稱為'BasicHttpBinding_IAxaptaService'和合同'AxaptaProxy.IAxaptaService'的終結點元素。 這可能是因為找不到您的應用程序的配置文件,或者是因為在客戶端元素中找不到與該名稱匹配的端點元素。
我搜索了很多位,我認為問題是由於我的DLL在另一個程序中運行所致。 有一些關於將EndPoint配置從應用程序復制到服務的文章,但是我不太了解應該做的事情。
有人對我如何進行這項工作有想法嗎?
我的客戶端創建的App.Config是這樣的:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IAxaptaService" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:4726/LM/AxaptaService.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IAxaptaService"
contract="AxaptaProxy.IAxaptaService" name="BasicHttpBinding_IAxaptaService" />
</client>
</system.serviceModel>
</configuration>
我試圖將其合並到托管Web服務的站點上的web.config中,如下所示:
<system.serviceModel>
<bindings>
<customBinding>
<binding name="GetStream.customBinding0">
<binaryMessageEncoding/>
<httpTransport/>
</binding>
</customBinding>
<basicHttpBinding>
<binding name="BasicHttpBinding_IAxaptaService" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="AutoCompletionAspNetAjaxBehavior">
<enableWebScript/>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
<services>
<service name="AutoCompletion">
<endpoint address="" behaviorConfiguration="AutoCompletionAspNetAjaxBehavior" binding="webHttpBinding" contract="AutoCompletion"/>
</service>
<service name="GetStream">
<endpoint address="" binding="customBinding" bindingConfiguration="GetStream.customBinding0" contract="GetStream"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<client>
<endpoint address="http://localhost:4726/LM/AxaptaService.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IAxaptaService"
contract="AxaptaProxy.IAxaptaService" name="BasicHttpBinding_IAxaptaService" />
</client>
</system.serviceModel>
已經有一些其他的東西了。 我可以刪除它們,如果這樣更容易。 我留給他們,以防他們對此產生影響。
因此,我從獨立的winform應用程序測試了該服務,並且運行良好。 可能是因為App.config嗎? 是否為.dll加載了我的配置?
您需要將連接信息從MyDll.dll.config復制到Web.config。
請小心合並配置部分,而不是簡單地並排添加或替換新數據。 如果已經有相同名稱的部分,則可能必須將它們合並。
這是一篇描述app.config的WCF部分內容的文章:
http://msdn.microsoft.com/en-us/library/ms734663.aspx
主要部分是:
<system.serviceModel>
<bindings>
<!-- various bindings go here... -->
</bindings>
<client>
<!-- endpoints go here... -->
</client>
</system.serviceModel>
您需要將這些節點中的所有內容組合在一起-將各種類型的endpoint
元素和binding
元素添加到服務的web.config中。
因此,如果您的配置如下所示:
<system.serviceModel>
<bindings>
<someBindingType name="someBinding" />
</bindings>
<client>
<endPoint name="someEndpoint />
</client>
</system.serviceModel>
您需要復制someBindingType
和endPoint
元素。 整個元素,包括結束標記(如果有)和子元素。
確保您沒有重復system.serviceModel
, bindings
或client
元素。 如果它們已經存在,請合並到其中,而不是創建新元素/復制。
我終於得到它的工作!
問題是,我的.dll項目中沒有加載app.config。 為了解決這個問題,我用代碼創建了綁定,而不是通過app.config來創建綁定,如該線程中所述: WCF配置不帶配置文件
謝謝您的所有幫助。 梅林,沒有你的幫助,我什至不會走這么遠。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.