mardi 6 février 2018

ASP.NET web service throwing not defined error on consumption

I've coded my first ASP.NET web service in VS 2010 (I know, we're nearly finished with a major version upgrade but I've got a legacy problem). We are getting pressure from our payment gateway to move to TLS 1.2, but our app is on Framework 2, so that is not an option. Decided instead to write a service that will run on Framework 4, use that to submit to the payment gateway, and call it from our v2 ASP.NET web site.

I can browse to my service and it works just fine, however when trying to consume it from the calling page I am getting a "MyServiceName is not defined" error. Both the main app and the service have their own folders under a "Webs" directory. The service seems to register fine in my main app solution. My svcinfo and wsdl files are being created. enter image description here

I am Importing the PaymentService at the top of the consuming page. The code that consumes and processes the result is as follows, with "Dim PS As PaymentService = New PaymentService" being the offending line:

Dim PS As PaymentService = New PaymentService
Dim strResult As String
strResult = PS.ProcessCCPayment(txtInvoiceID, strDescription, txtCustomerID, txtCreditCardNo, ExpirationDate, txtSecurityCode, totalPrice, txtCardHolderFName, txtCardHolderLName, _
                        txtAddress1, txtState, txtZip, txtCompanyName, txtBillingCity, txtBillingState, txtBillingZip)
Dim response_array As Array = Split(strResult, post_values("x_delim_char"), -1)

iResult = response_array(CC_RetCodes.ResponseCode)

The web.config file for the consuming page has the following:

<system.serviceModel>
    <bindings>
        <basicHttpBinding>
            <binding name="PaymentServiceSoap" />
        </basicHttpBinding>
    </bindings>
    <client>
        <endpoint address="http://ps.mydomain.com/PaymentService.asmx"
            binding="basicHttpBinding" bindingConfiguration="PaymentServiceSoap"
            contract="PaymentService.PaymentServiceSoap" name="PaymentServiceSoap" />
    </client>
</system.serviceModel>

One thing I thought was strange was that I was getting errors in the service's web.config file until I commented out these lines:

<!--<section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>-->
      <!--<sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
        <section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="Everywhere" />
        <section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" />
        <section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" />
        <section name="roleService" type="System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" />
      </sectionGroup>-->

I'm sure I've made a rookie mistake. A thousand thank-yous to anyone who can spot it!
Thanks! Mike




Aucun commentaire:

Enregistrer un commentaire