drmohundro / SWXMLHash

Simple XML parsing in Swift
MIT License
1.41k stars 205 forks source link

error 500 in some cases #128

Closed unosbaghaie closed 7 years ago

unosbaghaie commented 7 years ago

hi

I am using the below code and some other method in my web service which works correctly

 public func SendMessageToCustomersClubCategory(userName:String, password:String, messageBody:String, customerClubCategoryId:Int, SendDateTime:NSDate?, message:String)-> ArrayOfLong{
        var soapReqXML:String = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"

//        soapReqXML  += "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""
//        soapReqXML  += " xmlns:xsd =\"http://www.w3.org/2001/XMLSchema\""
//        soapReqXML  += " xmlns:soap =\"http://schemas.xmlsoap.org/soap/envelope/\">"
//        soapReqXML += " <soap:Body>"
//        soapReqXML += "<SendMessageToCustomersClubCategory xmlns=\"http://tempuri.org/\">"
//        soapReqXML += "<userName>"
//        soapReqXML += userName
//        soapReqXML += "</userName>"
//        soapReqXML += "<password>"
//        soapReqXML += password
//        soapReqXML += "</password>"
//        soapReqXML += "<messageBody>"
//        soapReqXML += messageBody
//        soapReqXML += "</messageBody>"
//        soapReqXML += "<customerClubCategoryId>"
//        soapReqXML += String(customerClubCategoryId)
//        soapReqXML += "</customerClubCategoryId>"
//        soapReqXML += "<SendDateTime"
//        if SendDateTime == nil {
//            soapReqXML += "xsi:nil=\"true\" />"
//        }
//            
//        else {
//            soapReqXML += ">"
//            soapReqXML += dateToString(date: SendDateTime as! Date)
//            soapReqXML += "</SendDateTime>"
//        }
//        soapReqXML += "<message>"
//        soapReqXML += message
//        soapReqXML += "</message>"
//        soapReqXML += "</SendMessageToCustomersClubCategory>"
//        soapReqXML += "</soap:Body>"
//        soapReqXML += "</soap:Envelope>"

        soapReqXML  += "<soap12:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""
        soapReqXML  += " xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\""
        soapReqXML  += " xmlns:soap12=\"http://www.w3.org/2003/05/soap-envelope\">"
        soapReqXML += " <soap12:Body>"
        soapReqXML += "<SendMessageToCustomersClubCategory xmlns=\"http://tempuri.org/\">"
        soapReqXML += "<userName>"
        soapReqXML += userName
        soapReqXML += "</userName>"
        soapReqXML += "<password>"
        soapReqXML += password
        soapReqXML += "</password>"
        soapReqXML += "<messageBody>"
        soapReqXML += messageBody
        soapReqXML += "</messageBody>"
        soapReqXML += "<customerClubCategoryId>"
        soapReqXML += String(customerClubCategoryId)
        soapReqXML += "</customerClubCategoryId>"
        soapReqXML += "<SendDateTime"
        if SendDateTime == nil {
            soapReqXML += "xsi:nil=\"true\" />"
        }

        else {
            soapReqXML += ">"
            soapReqXML += dateToString(date: SendDateTime as! Date)
            soapReqXML += "</SendDateTime>"
        }
        soapReqXML += "<message>"
        soapReqXML += message
        soapReqXML += "</message>"
        soapReqXML += "</SendMessageToCustomersClubCategory>"
        soapReqXML += "</soap12:Body>"
        soapReqXML += "</soap12:Envelope>"
        let soapAction :String = "http://tempuri.org/SendMessageToCustomersClubCategory"

        let responseData:Data = SoapHttpClient.callWS(Host : self.Host,WebServiceUrl:self.Url,SoapAction:soapAction,SoapMessage:soapReqXML)
        let returnValue:ArrayOfLong=SendMessageToCustomersClubCategoryResultFromXML(data : responseData)
        return returnValue
    }  

but it returnes

httpResponse.description    String  "<NSHTTPURLResponse: 0x608000223720> { URL: http://ipe.sms.ir/ws/app.asmx } { status code: 500, headers {\n    \"Cache-Control\" = private;\n    Connection = close;\n    \"Content-Length\" = 1935;\n    \"Content-Type\" = \"application/soap+xml; charset=utf-8\";\n    Date = \"Tue, 09 May 2017 09:04:21 GMT\";\n    Server = \"Microsoft-IIS/7.5\";\n    \"X-AspNet-Version\" = \"4.0.30319\";\n    \"X-Powered-By\" = \"ASP.NET\";\n} }" 

I am using these in Android and .Net and everything works fine . Could you help me . Sorry if my problem is not related

drmohundro commented 7 years ago

Hi, this is unrelated to SWXMLHash - this looks like XML that you're writing manually to send to the web service. SWXMLHash isn't even referenced in the code snippet you sent.

Chances are good that, if you can see any exceptions or event log details coming from the ASP.NET web service, you'll see where the error actually is coming from.

unosbaghaie commented 7 years ago

it was about datetime which from swift I was passing to asp.net I omitted datetime in an overload of that method and solved sorry I bothered you