Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/visual-studio-2010/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
C# WCF端点快把我逼疯了_C#_.net 3.5_Wcf - Fatal编程技术网

C# WCF端点快把我逼疯了

C# WCF端点快把我逼疯了,c#,.net-3.5,wcf,C#,.net 3.5,Wcf,也许我只是不明白,但我有一个部署到IIS 6机器上的服务。那台机器有一个局域网地址和一个公共互联网地址 我究竟该如何发布这项服务,使两者都可以访问 地址1: 地址2: 起初我想:没什么大不了的,两个端点。所以我有 <endpoint address="Address 1" binding="wsHttpBinding" bindingConfiguration="DefaultBindingConfiguration" name="RemoteE

也许我只是不明白,但我有一个部署到IIS 6机器上的服务。那台机器有一个局域网地址和一个公共互联网地址

我究竟该如何发布这项服务,使两者都可以访问

  • 地址1:
  • 地址2:
起初我想:没什么大不了的,两个端点。所以我有

<endpoint 
    address="Address 1" 
    binding="wsHttpBinding" 
    bindingConfiguration="DefaultBindingConfiguration" 
    name="RemoteEndpoint" />

<endpoint
    address="Address 2" 
    binding="wsHttpBinding" 
    bindingConfiguration="DefaultBindingConfiguration" 
    name="LocalEndpoint" />
没有骰子。无法添加服务引用

没有与给定地址“地址1”匹配的协议绑定。协议绑定在IIS或WAS配置中的站点级别配置

然后我想:也许主机标签和它的dns标签会有所帮助。不,那是认证用的

然后我想:我将使用net.tcp作为本地端点。哎呀。。。IIS 6不支持net.tcp

然后我想:我知道,ProxyClient构造函数将remoteAddress字符串作为第二个参数。现在它看起来像:

<endpoint
    address="" 
    binding="wsHttpBinding" 
    bindingConfiguration="DefaultBindingConfiguration" 
    name="MyEndpointName" />

public void createServiceProxy()
{
    if (Util.IsOperatingLocally())
        this.proxy = new ProxyClient("MyEndpointName", "Address 1");
    else
        this.proxy = new ProxyClient("MyEndpointName", "Address 2");
}

public void createServiceProxy()
{
if(Util.IsOperatingLocally())
this.proxy=newproxyclient(“MyEndpointName”、“地址1”);
其他的
this.proxy=newproxyclient(“MyEndpointName”、“地址2”);
}
显然不是。尝试实例化ProxyClient时

在ServiceModel客户端配置部分中找不到名为“MyEndpointName”和合同MyService.IService”的终结点元素

这使我找到app.config,其生成的客户端部分如下所示:

<client>
    <endpoint address="http://localhost:3471/Service.svc" binding="customBinding"
        bindingConfiguration="MyEndpointName" contract="MyService.IService"
        name="MyEndpointName">
        <identity>
            <userPrincipalName value="DevMachine\UserNa,e" />
        </identity>
    </endpoint>
</client>

在我看来,这肯定不对

我的下一个想法不是健康的。请帮忙。

以下是我的工作:

PortClient client = new PortClient(); // from the service reference

EndpointAddress endpointAddress;

if (local)
    endpointAddress = new EndpointAddress("http://local/Service.svc");
else
    endpointAddress = new EndpointAddress("http://remote/Service.svc");

client.ChannelFactory.CreateChannel(endpointAddress);
client.RemoteMethod();

等等。

您是否真的将字符串“地址1”和“地址2”放入了配置文件中

框架总是解析地址以了解要使用的传输。例如“http://myurl“将使用http”net。pipe://localhost/MyNamedPipeExample“将使用IPC

导致此错误的原因是字符串“Address 1”中没有前缀

我相信这会奏效,而无需硬编码地址:

<endpoint 
    address="http://serverName/ServiceName/Service.svc" 
    binding="wsHttpBinding" 
    bindingConfiguration="DefaultBindingConfiguration" 
    name="RemoteEndpoint" />

<endpoint
    address="http://www.companyName.com/ServiceName/Service.svc" 
    binding="wsHttpBinding" 
    bindingConfiguration="DefaultBindingConfiguration" 
    name="LocalEndpoint" />

为了防止它被使用,我在更新版本的IIS中遇到了相同的错误。在这种情况下,一种可能是只指定一个端点,并将地址保留为空字符串。然后将以下内容添加到服务的web.config的system.serviceModel部分:

<serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>

我在IE中浏览到我的第二个地址时遇到了协议绑定错误,所以我想解决这个问题,而不仅仅是在客户端使用解决方法


更多关于
multipleSiteBindingsEnabled
设置的信息,请点击此处:

有一天,我可以向您介绍小奥塔维奥。谢谢。@SnOrfus-很高兴能为您提供帮助,并感谢您的荣幸:-)不,我是在isp转发setyo的地方给他们打电话的(本地)和(远程),远程地址是:。这些地址是可浏览的。抱歉,只是绝对确定(因为标记可能已经吞没了您的一些评论)。您是否在地址名中添加了“http://”前缀?如果不是,那就可以解释错误。
<serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>