2012-08-14 40 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()