简体   繁体   中英

Simple C# Web Service Works Locally but not on Server

i have a C# web Service, it is very simple,

i have web reference that uses an external WSDL,

Works locally on company machine but not on a company Server.

i have seen on other posts this might be proxy related, but i have tired a few different edits to the webconfig regarding proxy, but i need help from the experts.

When i press invoke when the webservice is running on the server through the browser i am getting the error "Unable to connect to the remote server".

<?xml version="1.0" encoding="utf-8" ?>
<string xmlns="http://www.service-now.com/CatalogUpdateAutomationVariables">Unable to connect to the remote server</string> 

WEB CONFIG

<?xml version="1.0"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
  <configSections>
    <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <section name="InboundServiceNowWeb.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
    </sectionGroup>
  </configSections>
  <system.web>
    <compilation targetFramework="4.5.2" debug="true"/>
    <httpRuntime targetFramework="4.5.2"/>
    <customErrors mode="Off"/>
    <webServices>
      <protocols>
        <add name="HttpGet"/>
        <add name="HttpPost"/>
      </protocols>
    </webServices>
  </system.web>
  <system.codedom>
    <compilers>
      <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701"/>
      <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+"/>
    </compilers>
  </system.codedom>
  <system.serviceModel>
    <bindings/>
    <client/>
  </system.serviceModel>
  <applicationSettings>
    <InboundServiceNowWeb.Properties.Settings>
      <setting name="InboundServiceNowWeb_ServiceNowDev_ServiceNow_CatalogUpdateAutomationVariables" serializeAs="String">
        <value>https://COMPANY.service-now.com/CatalogUpdateAutomationVariables.do?SOAP</value>
      </setting>
    </InboundServiceNowWeb.Properties.Settings>
  </applicationSettings>
  <system.net>
    <defaultProxy enabled="true" useDefaultCredentials="false" />
  </system.net>
</configuration>
<!--ProjectGuid: {55A9796B-1C01-4454-B0C3-942C1C8221B5}-->

C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;

namespace InboundServiceNowWeb
{
    /// <summary>
    /// Summary description for ServiceNowInboundSOAP
    /// </summary>
    [WebService(Namespace = "http://www.service-now.com/CatalogUpdateAutomationVariables")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class ServiceNowInboundSOAP : System.Web.Services.WebService
    {

        [WebMethod]
        public string UpdateCatalogRITM(string RITM, string ReturnCode, string ReturnMessage, string Comment)
        {
            // return "Hello World1";
            /*
             //SERVICE REFERENCE-SPECIFIC CODE  
             ServiceNowDev.ServiceNowSoapClient soapClient = new ServiceNowDev.ServiceNowSoapClient();
             soapClient.ClientCredentials.UserName.UserName = "sys_ws_catalog";
             soapClient.ClientCredentials.UserName.Password = "#####";

             ServiceNowDev.update insert = new InboundServiceNowWeb.ServiceNowDev.update();
             //ServiceNowDEV.update response = new ServiceNowDEV.updateResponse();
             ServiceNowDev.updateResponse response = new InboundServiceNowWeb.ServiceNowDev.updateResponse();
             */
            //   WEB REFERENCE-SPECIFIC CODE
            ServiceNowDev.ServiceNow_CatalogUpdateAutomationVariables soapClient = new InboundServiceNowWeb.ServiceNowDev.ServiceNow_CatalogUpdateAutomationVariables();
            System.Net.ICredentials cred = new System.Net.NetworkCredential("sys_ws_catalog", "catalog01");
            soapClient.Credentials = cred;

            ServiceNowDev.update insert = new ServiceNowDev.update();
            ServiceNowDev.updateResponse response = new ServiceNowDev.updateResponse();
            //   END OF WEB REFERENCE CODE */

            insert.RequestNumber = RITM;
            insert.ReturnCode = ReturnCode;
            insert.ReturnMessage = ReturnMessage;
            insert.Comments = Comment;

            try
            {
                response = soapClient.update(insert);
                return response.result;

            }
            catch (Exception error)
            {
                return error.Message;
               // this.Response.Text = error.Message;
            }
        }
    }
}

After a few tweaks to the company firewall for the servers i was able to connect successfully.

Thanks for your help

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM