2013-08-06 213 views
1

我在經典ASP調用WCF服務中的方法時遇到問題。下面是服務和配置的代碼:從經典ASP呼叫WCF服務

<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測試客戶端測試上述方法

服務

[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 
} 

配置和正常工作。下面是從我的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 error '800401e4'

The contract does not have an endpoint supporting the binding specified.

我試過在綽號傳遞綁定配置名稱BasicHttpBinding_PdfGenerator,而不是basicHttpBinding但我犯了同樣的錯誤。我在網上找不到任何其他這種錯誤的例子。

任何幫助,將不勝感激

回答

0

您可以使用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);     
} 
+0

感謝您的回覆。根據無數的在線演示,我讀過我的原代碼應該工作。無論是服務的配置還是我正在構建的綽號,都有問題。有很多人在做我正在做的事情的例子,不幸的是,似乎沒有人遇到與我一樣的錯誤!非常沮喪 –

+0

理解..我想如果你不能讓你的ASP版本工作,你可以試試我在做什麼。它很容易插入任何HTML/ASP類型構造。 – Brian