【问题标题】:Error in using WCF service使用 WCF 服务时出错
【发布时间】:2011-08-27 18:53:38
【问题描述】:

当我尝试使用我的服务时遇到以下错误。

There was no endpoint listening at http://myip:84/service1.svc/ that could accept the message. This is often caused by an incorrect address or SOAP action.

我的服务代码:

<system.serviceModel>

        <services>
            <service name="wcftest1.Service1" behaviorConfiguration="wcftest1.Service1Behavior">


                <endpoint address="http://myip:84/Service1.svc/" behaviorConfiguration="epbeh" bindingConfiguration ="webConfig" binding="webHttpBinding" contract="wcftest1.IService1">
                </endpoint>

                <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>

            </service>

        </services>

        <bindings>
            <basicHttpBinding>
                <binding name="basicConfig" >
                </binding>
            </basicHttpBinding>
            <webHttpBinding>
                <binding name="webConfig">

                </binding>

            </webHttpBinding>

        </bindings>
        <behaviors>
            <serviceBehaviors>
                <behavior name="wcftest1.Service1Behavior" >
                    <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->

                    <serviceMetadata httpGetEnabled="true" />
                        <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
                    <serviceDebug includeExceptionDetailInFaults="false"/>
                    <serviceCredentials>
                        <userNameAuthentication userNamePasswordValidationMode="Custom"  customUserNamePasswordValidatorType="wcftest1.validateUser, wcftest1"/>
                    </serviceCredentials>

                </behavior>
            </serviceBehaviors>
            <endpointBehaviors>
                <behavior name="epbeh">
                    <webHttp />
                </behavior>
            </endpointBehaviors>
        </behaviors>

服务类:

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class Service1 : IService1
    {

服务接口:

[OperationContract]
        [WebGet(ResponseFormat= WebMessageFormat.Json)]
        string GetMsg();

客户端网络配置:

    <system.serviceModel>
        <bindings>
   <customBinding>
    <binding name="WebHttpBinding_IService1">
     <textMessageEncoding maxReadPoolSize="64" maxWritePoolSize="16"
      messageVersion="Soap12" writeEncoding="utf-8">
      <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
       maxBytesPerRead="4096" maxNameTableCharCount="16384" />
     </textMessageEncoding>
        <httpTransport/>
    </binding>

   </customBinding>
  </bindings>
        <client>
   <endpoint binding="customBinding" address="http://myip:84/service1.svc/" bindingConfiguration="WebHttpBinding_IService1"
    contract="ServiceReference1.IService1" name="WebHttpBinding_IService1" />
  </client>
    </system.serviceModel>

客户端代码:

 ServiceReference1.Service1Client sc = new userwcftest1.ServiceReference1.Service1Client();

            Response.Write(sc.GetData(5));

我的服务将由 PHP 开发人员使用,它基于 .NET 框架 3.5 构建,我将返回 JSON。 我是 WCF 的新手。

请帮帮我 谢谢

【问题讨论】:

  • 如果您正在寻找基于 REST 的服务(因为您有 webhttpbinding),请查看 WCF REST starter kit。
  • @Aravind:谢谢你的建议……让我检查一下。
  • 您在服务端有Service1,在客户端有service1。我相信在.net 的某些部分中,URI 是区分大小写的。使它们相同。

标签: .net wcf json .net-3.5


【解决方案1】:

客户端使用与服务不同的绑定 - 客户端使用消息版本 SOAP 1.2 的自定义绑定;服务器使用 webHttpBinding,大致相当于使用 MessageVersion.None 的自定义绑定(它是 REST,而不是 SOAP)。

您在服务上添加了 mex 端点,但 REST 端点不发出元数据,因此您使用 svcutil / add service reference 生成的任何内容都不起作用。

调用服务的一种方法是简单地使用以下内容:

WebClient c = new WebClient();
string result = c.DownloadString("http://myip:84/service1.svc/GetMsg");

【讨论】:

  • 您在寻找哪些详细信息?如果您使用 Add Service Reference 或 svcutil 为 REST 端点创建客户端,它将不起作用。查看 ServiceReference1\Reference.cs 中的客户端接口 - 操作 GetData 未使用 [WebGet] 属性进行修饰 - 该客户端无法与服务一起使用(除非已修改)。
猜你喜欢
  • 2015-03-10
  • 1970-01-01
  • 1970-01-01
  • 2011-08-06
  • 1970-01-01
  • 2013-05-28
  • 2015-12-29
  • 1970-01-01
相关资源
最近更新 更多