Orchard:使用Module中的Webservice

时间:2012-08-14 09:27:42

标签: soap web-config orchardcms

我需要在模块中使用现有的SOAP-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不在Orchard-Root中。

最好做些什么?

THX 莱因哈德

1 个答案:

答案 0 :(得分:0)

您可以使用

使用web.config
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();

但我不建议这样做,基本上你必须使用自己的设置扩展siteSettings内容部分,并在那里存储地址和绑定信息。然后在您自己的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()
相关问题