Search code examples
c#magentomagento-1.9

Cannot login Magento service using C# [Magento 1.9.3.3] Error: Premature end of data in tag html line 7


I'm developing a C# Winapp to communicate with the Magento Server. I'm trying to login into Magento service to add customer data but I can't get pass the login sequence.

This is my login code in C#

PortTypeClient mservice = new PortTypeClient();
string mlogin = mservice.login("user", "password"); 

And this is my app.config file

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <configSections>
    </configSections>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="BTVBinding" maxReceivedMessageSize="2000000">
                    <security mode="Transport" />
                </binding>
            </basicHttpBinding>
        </bindings>
        <client>
          <endpoint address="https://admin.mywebsite.com/index.php/api/v2_soap/index"
              binding="basicHttpBinding" bindingConfiguration="BTVBinding"
              contract="BTVMagento.PortType" name="Port1" >
          </endpoint>
        </client>
    </system.serviceModel>

I always got this error

System.ServiceModel.FaultException: 'SOAP-ERROR: Parsing WSDL: Couldn't load from 'https://admin.mywebsite.com/index.php/api/v2_soap/index/?wsdl=1' : Premature end of data in tag html line 7

Solution

  • Found out the error caused by my endpoint redirected my API request to the website's homepage. The homepage's HTML code started at line 7 (Below 6 lines of comments). That's why it said Error: Premature end of data in tag html line 7.