2012-08-14 110 views
0

我需要使用我正在編寫的模塊中現有的SOAP-Webservice。果園:在模塊中使用Webservice

我我模塊的web.config中包含:

<system.serviceModel> 
<bindings> 
    <basicHttpBinding> 
    <binding name="WebShopServiceSoap" 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://10.0.0.123/LCWebservices/LC.MiscService/webshopservice.asmx" 
    binding="basicHttpBinding" bindingConfiguration="WebShopServiceSoap" 
    contract="LCWebshopServiceReference.WebShopServiceSoap" name="WebShopServiceSoap" /> 
</client> 

但我模塊拋出

Oops. Something went wrong ... sorry 
An unhandled exception has occurred and the request was terminated. 
Please refresh the page. If the error persists, go back 

Es wurde kein standardmäßiges Endpunktelement gefunden, das auf den Vertrag 
"LCWebshopServiceReference.WebShopServiceSoap" im ServiceModel- 
Clientkonfigurationsabschnitt verweist. 
Dies kann folgende Ursachen haben: Für die Anwendung wurde keine 
Konfigurationsdatei gefunden, oder im Clientelement wurde kein 
Endpunktelement gefunden, das diesem Vertrag entsprach. 

大致翻譯,端點元素不能被發現。 我懷疑這是由於這個事實,這個web.config不駐留在果園根。

這是怎麼回事?

THX 萊因哈德

回答

0

你可以使用使用

Configuration configuration = ConfigurationManager.OpenMappedExeConfiguration(
       new ExeConfigurationFileMap { ExeConfigFilename = HostingEnvironment.ApplicationPhysicalPath + @"/Modules/MyModule/Web.config" }, ConfigurationUserLevel.None); 

     var factory = new ConfigurationChannelFactory<IMyService>("IMyService", configuration, null); 
     var client = factory.CreateChannel(); 
     client.MyMethod(); 

web.config中,但我不會推薦這,basicly你必須用你自己的設置擴展站點設置內容部分和存儲地址並在那裏綁定信息。然後在您自己的IoC服務類中使用這些設置。

服務類可以創建一個綁定和一個ChannelFactory來調用Web服務。

var factory = new ChannelFactory<WorkflowServiceRef.IWorkflowService>(
      binding, 
      new EndpointAddress(endpointUri)); 
factory.Credentials.SupportInteractive = false; 
factory.ConfigureChannelFactory(); 
var channel = factory.CreateChannel(); 

channel.MyMethod()