【问题标题】:Call WCF service from classic ASP从经典 ASP 调用 WCF 服务
【发布时间】:2013-08-06 10:16:58
【问题描述】:

我在从经典 ASP 调用 WCF 服务中的方法时遇到问题。下面是服务和配置的代码:

服务

[ServiceContract(Namespace = "http://Plumtree.dartKW.PdfGenerator.Web")]
public interface IPdfGeneratorService
{
    [OperationContract]
    String GeneratePdf(String xml);
}

public class PdfGeneratorService : IPdfGeneratorService
{
    #region IPdfGeneratorService Members

    public String GeneratePdf(String xml)
    {
        return "hello";
    }

    #endregion
}

配置

<system.serviceModel>
  <bindings>
    <basicHttpBinding>
      <binding name="BasicHttpBinding_PdfGenerator"
               maxBufferSize="2147483647"
               maxReceivedMessageSize="2147483647"
               maxBufferPoolSize="2147483647"
               transferMode="Buffered">
        <readerQuotas
          maxArrayLength="2147483647"
          maxStringContentLength="2147483647"
          maxBytesPerRead="2147483647"
          maxNameTableCharCount="2147483647"
          maxDepth="32" />
      </binding>
    </basicHttpBinding>
  </bindings>
  <services>
    <service behaviorConfiguration="serviceBehavior"
             name="Plumtree.dartKW.PdfGenerator.Web.PdfGeneratorService">
      <endpoint binding="basicHttpBinding"
                bindingName="BasicHttpBinding_PdfGenerator"
                contract="Plumtree.dartKW.PdfGenerator.Web.IPdfGeneratorService" />
      <endpoint address="mex"
                binding="mexHttpBinding"
                contract="IMetadataExchange" />
    </service>
  </services>
  <behaviors>
    <serviceBehaviors>
      <behavior name="serviceBehavior">
        <serviceMetadata httpGetEnabled="true" />
        <serviceDebug includeExceptionDetailInFaults="false" />
      </behavior>
    </serviceBehaviors>
  </behaviors>
  <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>

我已经在 WCF 测试客户端中测试了上述方法,它工作正常。这是我的asp页面中的代码:

mexMonikerString = "service:mexAddress='http://localhost:51997/PdfGeneratorService.svc/mex'"
mexMonikerString = mexMonikerString + ", address='http://localhost:51997/PdfGeneratorService.svc'"
mexMonikerString = mexMonikerString + ", binding=basicHttpBinding"
mexMonikerString = mexMonikerString + ", bindingNamespace='http://tempuri.org/'"
mexMonikerString = mexMonikerString + ", contract=IPdfGeneratorService"
mexMonikerString = mexMonikerString + ", contractNamespace='http://Plumtree.dartKW.PdfGenerator.Web'"

dim service
service = GetObject(mexMonikerString) 

每当我尝试这个时,我都会收到以下错误:

System.ServiceModel 错误“800401e4”

合约没有支持指定绑定的端点。

我尝试在名字对象中传递绑定配置名称 BasicHttpBinding_PdfGenerator 而不是 basicHttpBinding,但我得到了同样的错误。我在网上也找不到这个错误的任何其他例子。

任何帮助将不胜感激

【问题讨论】:

    标签: wcf asp-classic


    【解决方案1】:

    您可以使用 JavaScript 轻松完成。这是嵌入在简单 HTML 页面中的一些 JavaScript 的副本,我将它提供给我的潜在 WCF Web 服务用户。

    困难的部分可能是弄清楚 WCF 服务在请求中的期望。如果您有权访问 WCF 服务代码,则很容易弄清楚。另一种方法是使用 Fiddler 捕获客户端和 wcf 主机之间发送的成功消息。或者 WSDL,如果你能生成的话。

    祝你好运。

    function Ping() {             
    //set up varable
    var sContent;
    // 'Content-Type: text/xml \r\n ' +
    // 'Host: localhost:8085 \r\n \r\n  ';
    sContent=  "<xml>Your message matching the web service's data or message contract</xml>";
    
    var xmlhttp =  new XMLHttpRequest();
    xmlhttp.open('POST', Demo.URL.value, true);  
    xmlhttp.onreadystatechange = function() {
    //this section acts as a listener, waiting for response from host
    if (xmlhttp.readyState == 4||xmlhttp.readyState == 0) {
        //alert("Ready state: " + xmlhttp.readyState.toString());
        if (xmlhttp.status == 200) {
            //alert("good");
            Demo.pingresponse.value = "Response: " +xmlhttp.responseText;
        }
        if (xmlhttp.status !=200){
            //alert("bad");
            Demo.pingresponse.value = "Error: " +xmlhttp.status.toString() +"  response text:  " +xmlhttp.responseText;
        }
    } else {
        //alert("readystate bad");
    }
     }
     //send request    
    
    xmlhttp.setRequestHeader("POST http:localhost:8085/HostInterface/HostConnect HTTP/1.1"); 
    xmlhttp.setRequestHeader("VsDebuggerCausalityData",""); 
    xmlhttp.setRequestHeader   ("SOAPAction","\"http://somestuff\""); 
    xmlhttp.setRequestHeader("Host","localhost:8085"); 
    xmlhttp.setRequestHeader("Expect","100-continue"); 
    xmlhttp.setRequestHeader("Accept-Encoding","gzip, deflate"); 
    xmlhttp.setRequestHeader("Connection","Keep-Alive"); 
    xmlhttp.setRequestHeader("Content-Length","639");                   
    xmlhttp.setRequestHeader("Content-type", "text/xml; charset=utf-8"); 
    xmlhttp.send(sContent);                  
    }
    

    【讨论】:

    • 感谢您的回复。根据无数在线演示,我已经阅读了我的原始代码应该可以工作。服务的配置或我正在构建的名字对象存在问题。有很多人在做我想做的事情的例子,不幸的是,似乎没有人遇到与我相同的错误!很郁闷
    • 明白了.. 我想如果你的 ASP 版本不能工作,你可以试试我正在做的。它很容易插入到任何 HTML/ASP 类型结构中。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-05
    • 1970-01-01
    • 2010-11-29
    • 1970-01-01
    相关资源
    最近更新 更多