简体   繁体   English

在 IIS 中使用 URL 重写时,Web 服务无法公开访问

[英]Webservice is not accessible publicly when using URL rewrite in IIS

I hosted webservice in private server.我在私人服务器中托管了网络服务。 I then created URL rewrite rule in IIS which is there in public server(internet server).然后我在公共服务器(互联网服务器)中的 IIS 中创建了 URL 重写规则。

Everytime I access the URL, It explicitly shows the private server's ip/ computer name in URL on browser rather than public url/IP.每次我访问 URL 时,它都会在浏览器上的 URL 中明确显示私有服务器的 ip/计算机名称,而不是公共 url/IP。 When I click on the URL for viewing script, it shows "Example.svc does not exist" error.当我单击 URL 以查看脚本时,它显示“Example.svc 不存在”错误。

It also doesn't work when i try to add it as service reference in Visual studio by passing the URL in it.当我尝试通过在其中传递 URL 将其添加为 Visual Studio 中的服务引用时,它也不起作用。 It throws the below error.它引发以下错误。

The request failed with HTTP status 400: Bad request
Metadata contains a reference that cannot be resolved: <SERVER URL>
The remote server turned an unexpected response: (405) Method not allowed.

What should I do for accessing the URL publicly and also able to add it as reference in Visual studio.?我应该怎么做才能公开访问 URL 并且还能够将其添加为 Visual Studio 中的参考。?

It seems that you are deploying a WCF service in IIS.您似乎正在 IIS 中部署 WCF 服务。 Is that correct?那是对的吗? If the error “example.svc does not exists” occurred, please ensure that you have enabled certain Windows features in order to host WCF service in IIS.如果出现“example.svc does not exists”错误,请确保您已启用某些 Windows 功能,以便在 IIS 中托管 WCF 服务。
在此处输入图像描述
The reason why we cannot add it as Service Reference in order to call the service is that we have not published the Metadata service endpoint.我们无法将其添加为Service Reference以调用服务的原因是我们尚未发布元数据服务端点。 This depends on your WCF service type.这取决于您的 WCF 服务类型。 Generally, we either add a Mex service endpoint or publish the service WSDL by adding Metadata service behavior.通常,我们要么添加 Mex 服务端点,要么通过添加元数据服务行为发布服务 WSDL。

  <services>
    <service name="WcfService1.Service1">
      <endpoint address="" binding="basicHttpBinding" bindingConfiguration="mybinding" contract="WcfService1.IService1">
      </endpoint>
      <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"></endpoint>
    </service>
  </services>

  <behaviors>
        <serviceBehaviors>
          <behavior>
            <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />

Everytime I access the URL, It explicitly shows the private server's ip/ computer name in URL on browser rather than public url/IP.每次我访问 URL 时,它都会在浏览器上的 URL 中明确显示私有服务器的 ip/计算机名称,而不是公共 url/IP。

In order to access the service by using the hostname/domain name URL, we should ensure that the domain name points to the public IP of the server.为了使用主机名/域名URL访问服务,我们应该确保域名指向服务器的公共IP。 It is a network-related issue.这是一个与网络相关的问题。 在此处输入图像描述

Feel free to let me know if the problem still exists.如果问题仍然存在,请随时告诉我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM