Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/256.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/apache-kafka/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 无法从DLL调用WCF WebService_C#_Wcf_Web Services_Dll - Fatal编程技术网

C# 无法从DLL调用WCF WebService

C# 无法从DLL调用WCF WebService,c#,wcf,web-services,dll,C#,Wcf,Web Services,Dll,我试图调用一个WCF Web服务,从我制作的dll中调用,运行在我们的CAD软件中。 但是我不能让它工作 当我尝试建立代理时,出现以下错误: 在ServiceModel客户端配置节中找不到名为“BasichtpBinding_IAxaptaService”和约定为“AxaptaProxy.IAxaptaService”的终结点元素。这可能是因为找不到应用程序的配置文件,或者在客户端元素中找不到与此名称匹配的端点元素 我已经搜索了abit,我认为问题是由于我的DLL在另一个程序中运行。 有一些关于

我试图调用一个WCF Web服务,从我制作的dll中调用,运行在我们的CAD软件中。 但是我不能让它工作

当我尝试建立代理时,出现以下错误:

在ServiceModel客户端配置节中找不到名为“BasichtpBinding_IAxaptaService”和约定为“AxaptaProxy.IAxaptaService”的终结点元素。这可能是因为找不到应用程序的配置文件,或者在客户端元素中找不到与此名称匹配的端点元素

我已经搜索了abit,我认为问题是由于我的DLL在另一个程序中运行。 有一些关于将端点配置从应用程序复制到服务的文章,但我没有完全理解我应该做什么

有人知道我该怎么做吗

由我的客户端创建的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部分的核心内容:

主要作品有:

<system.serviceModel>
   <bindings>
     <!-- various bindings go here... -->
   </bindings>
   <client>
     <!-- endpoints go here... -->
   </client>
</system.serviceModel>
您需要复制
someBindingType
endPoint
元素。整个元素,包括结束标记(如果有)和子元素


确保不复制
系统.serviceModel
绑定
客户端
元素。如果它们已经存在,则合并到它们中,而不是创建新元素/复制。

我终于让它工作了

问题是,app.config没有在my.dll项目中加载。 为了解决这个问题,我在代码中创建了绑定,而不是通过app.config,如本文所述:


谢谢你的帮助。梅林,如果没有你的帮助,我甚至不会走到这一步。

我不完全确定如何做到这一点。它是绑定还是端点(或两者)?我应该把它合并到web.config中吗?我的web服务正在现有的ASP.NET网站上运行。@Nicolai:噢,这是一个web服务。不知什么原因,我以为你指的是Windows服务。是的,然后将数据合并到
web.config
中。我编辑了答案来解决这个问题。我希望我能理解这一点,但我显然没有。我已将绑定从App.config复制/粘贴到我的web.config中。我如何处理客户部分?我是否只是将整个客户端节点复制到web.config中?我试图将内容粘贴到web.config中的一个新服务节点中,但似乎没有任何效果。@Nicolai:对于绑定下的每个元素,请复制。对于客户端下的每个元素,复制。这意味着您将复制
wsHttpBinding
endpoint
等内容。您需要复制每个绑定和端点元素的全部,而不是每个元素的一部分。但是,如果结果是不止一个具有相同的名称,则会发生冲突。如果结果是这样,请将一些配置文件粘贴到问题中。@Nicolai:“新服务节点”-确保没有两个
system.serviceModel
节点、两个
绑定
节点或两个
客户端
节点。如果这些节点已经存在,则必须合并它们。如果应用程序名为myapp.exe,则需要将其复制到myapp.exe。config@Nicolai:这看起来基本上是对的。您尝试连接的服务在哪里?同一个盒子?还是另一个盒子?如果你在复制配置后出现同样的错误,我会很惊讶,并且我希望你现在会遇到不同的异常-可能是因为找不到服务。Merlyn:是的,现在都在我的本地主机上,VisualStudio的内部Web服务器上。我试着创建一个winform应用程序,并将服务引用添加到其中,效果很好。我猜是我的.dll出现了一些问题。
<system.serviceModel>
   <bindings>
     <someBindingType name="someBinding" />
   </bindings>
   <client>
     <endPoint name="someEndpoint />
   </client>
</system.serviceModel>