c# – 未找到端点 – WCF Web服务

前端之家收集整理的这篇文章主要介绍了c# – 未找到端点 – WCF Web服务前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我已经为我的WCF服务创建了2个端点.

它使用basicHttpBinding工作正常,但会导致webHttpBinding错误.

错误=未找到端点.

操作合同定义

[OperationContract]
[WebInvoke(Method = "POST",BodyStyle = WebMessageBodyStyle.WrappedRequest,ResponseFormat = WebMessageFormat.Json)]
VINDescription CallADSWebMethod(string vin,string styleID);

web.config中:

<system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="Description7aBinding" 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://services.chromedata.com:80/Description/7a"
                binding="basicHttpBinding"
                bindingConfiguration="Description7aBinding"
                contract="description7a.Description7aPortType"
                name="Description7aPort"/>
    </client>
    <services>
      <service behaviorConfiguration="asmx" name="ADSChromeVINDecoder.Service">
        <endpoint name="httpEndPoint" 
                  address="" 
                  binding="basicHttpBinding"
                  contract="ADSChromeVINDecoder.IService"/>
        <endpoint name="webEndPoint"
                  address="json"
                  behaviorConfiguration="web"
                  binding="webHttpBinding"
                  contract="ADSChromeVINDecoder.IService"/>
      </service>
    </services>
    <behaviors>
      <endpointBehaviors>
        <behavior name="web">
          <webHttp/>
          <enableWebScript/>
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior name="asmx">
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
  </system.serviceModel>

请建议我如何解决这个问题?

解决方法

我已经创建了一个类似的服务,你根据这个:
[ServiceContract]
public interface IService
{
    [OperationContract]
    [WebInvoke(UriTemplate="/CallADSWebMethod",Method="POST",ResponseFormat = WebMessageFormat.Json)]
    string CallADSWebMethod(string vin,string styleID);
}

添加的重要的是UriTemplate部分,告诉服务如何调用应该是这样的.然后我实现了这个服务:

public class Service : IService
{
    public string CallADSWebMethod(string vin,string styleID)
    {
        return vin + styleID;
    }
}

在我的web.config我有以下:

<system.serviceModel>
<bindings>
  <basicHttpBinding>
    <binding name="Description7aBinding" 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>
<services>
  <service behaviorConfiguration="asmx" name="WebApplication1.Service">
    <endpoint address="basic" binding="basicHttpBinding" name="httpEndPoint" contract="WebApplication1.IService"/>
    <endpoint address="json" binding="webHttpBinding" behaviorConfiguration="webBehavior" name="webEndPoint" contract="WebApplication1.IService"/>
    <endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
  </service>
</services>
<behaviors>
    <endpointBehaviors>
        <behavior name="webBehavior">
            <webHttp />
        </behavior>
    </endpointBehaviors>
    <serviceBehaviors>
    <behavior name="asmx">
      <serviceMetadata httpGetEnabled="true"/>
      <serviceDebug includeExceptionDetailInFaults="true"/>
    </behavior>
  </serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>

然后,我创建了一个简单的页面,看起来像这样使用jQuery调用这个服务:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $("#Ok").click(function () {
                var jData = {};
                jData.vin = "one";
                jData.styleID = "test";
                $.ajax({
                    type: "POST",url: "/Service.svc/json/CallADSWebMethod",data: JSON.stringify(jData),contentType: "application/json; charset=utf-8",dataType: "json",success: function (msg) {
                        alert(msg);
                    },error: function (jqXHR,textStatus,errorThrown) {
                        alert(textStatus);
                    }
                });
            });
        });
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <input type="button" id="Ok" name="Ok" value="Ok" />
    </div>
    </form>
</body>
</html>

这将产生一个警告与文本onetest.希望这可以给som指导.

原文链接:https://www.f2er.com/csharp/97100.html

猜你在找的C#相关文章