在远程Web服务器上部署的WCF restFULL服务抛出错误无法连接到远程服务器

时间:2015-12-02 09:42:13

标签: c# wcf

我开发了WCF RestFul服务并创建了GET和POST方法。 并在互联网服务器上托管

问题: 至于我的生产机器,每件事都很好,Get Method返回数据; POST方法将数据插入db。 但是当我在远程(互联网)服务器上运行时,GET方法很流畅 但是POST方法抛出Exception并带有内部异常,这里是Excepion

主要例外:无法连接到远程服务器 和内部异常:“由于目标机器主动拒绝它,因此无法建立连接127.0.0.1:8888”

我该怎么做。

这是代码(客户端)示例

Orders o = new Orders
    {
        OrderId = 1,
        Dated = DateTime.Now.Date.ToString("dd/MM/yyyy"),
        PartyCode = "1001",
        PartyName = "Adnan Umar",
        UserName="mau",
        lstOrderDetail = new List<LineItem>() 
        { new LineItem { SrNo = 1, ProductCode = "101", ProductName = "Mouse", Qty = 70, Discount = 0 }, 
          new LineItem { SrNo = 2, ProductCode = "301", ProductName = "KeyBoard", Qty = 90, Discount = 0 } ,
          new LineItem { SrNo = 3, ProductCode = "501", ProductName = "Mobile", Qty = 1980, Discount = 0 } 
        }
    };

    DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(Orders));
    MemoryStream mem = new MemoryStream();
    ser.WriteObject(mem, o);

    string s = Encoding.UTF8.GetString(mem.ToArray());




    WebClient webClient = new WebClient();
    webClient.Headers[HttpRequestHeader.ContentType] = "application/json";
    webClient.Encoding = Encoding.UTF8;

    try
    {
        //webClient.UploadData("http://localhost:54144/RestServiceIMP.svc/SaveOrder","POST",mem.ToArray()); //working g8
        webClient.UploadData("InternetAddress/restserviceimp.svc/SaveOrder", "POST", mem.ToArray());//not working



    }
    catch (Exception ex)
    {
        Console.WriteLine(ex.Message);
    }er

这是SVC类

   [OperationContract]
[WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "json/{id}")]
List<myProduct> JSONData(string id);

[OperationContract]
[WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "jsonParty/{id}")]
List<myParty> JSONPartyData(string id);

/*
[OperationContract]
[WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json, BodyStyle=WebMessageBodyStyle.Wrapped , UriTemplate = "updateOrder")]
int UpdateOrderAddress(Stream JSONdataStream);
 * */

[OperationContract]
[WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare, UriTemplate = "SaveOrder")]
int SaveOrder(OrdersMain JSONdataStream);

这是配置文件

<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>

    <services>

      <service name="RESTService.RestServiceIMP" behaviorConfiguration="ServiceBehaviour">
        <endpoint address="" binding="webHttpBinding" contract="RESTService.IRestServiceIMP" behaviorConfiguration="web"></endpoint>
        <endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex"></endpoint>

      </service>

    </services>

    <behaviors>

      <serviceBehaviors>
        <behavior name="ServiceBehaviour">
          <!-- 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"/>

        </behavior>

      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="web">
          <webHttp/>
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />


  </system.serviceModel>

 <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>

  </system.webServer>
</configuration>

0 个答案:

没有答案