function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Custom WebService Call from .NET / Unhandled Exception


I have written a custom APEX WebService that I am trying to use in .NET. When I am trying to call a method using webservice, it is giving me a SOAP Header Exception,. Not sure what the exception means and please let me know if i am doing something wrong here. Appreciate your response.
APEX WS Class - 
global class putLocationId {
  webservice String City;
  webservice String State;
  global class LocationInput {
    webservice String GUID; 
    webservice String locationinfo;
    webservice String LocationId;
 global class LocationOutput {
    webservice String errorMessage; 
    webservice boolean Success;
  webservice static LocationOutput createLocationws(List<LocationInput> vlocationinfo) {
     integer newcount = 0;
     List<Location__c> newloc = new List<Location__c>();
     for (integer i = 0; i < vlocationinfo.size() ; i++) {
     Location__c l = new Location__c();
     l.Location_ID__c = vlocationinfo[i].GUID;
     l.Name__c = vlocationinfo[i].locationinfo;
     l.LocationIntStatusLastChanged__c =;
     l.Current_Backlog_Minutes__c = 100;
     l.Postal_Code__c = '03801';
     newcount = newcount + 1;
     insert newloc;
     system.debug(' the locations added:'  + newcount);   
     LocationOutput ops = new LocationOutput();
     ops.errorMessage = 'No Errors from this API';
     ops.success = true;
     return ops;
.NET Code calling this WS is 
            SforceService sforceService = new SforceService();
            LoginResult loginResult = putLocationIdService.login("xxxxxx", "xxxxxxx");
            putLocationIdService locService = new putLocationIdService();
            putLocationId.SessionHeader header = new putLocationId.SessionHeader();
            enterprise.SessionHeader header1 = new enterprise.SessionHeader();
            locService.SessionHeaderValue = header;
            header.sessionId = loginResult.sessionId;
            locService.Url = loginResult.serverUrl;
                LocationInput input1 = new LocationInput();
                input1.GUID = "10101010";
                input1.LocationId = "L1500";
                input1.locationinfo = "Test Location 1";
                LocationInput input2 = new LocationInput();
                input2.GUID = "20202020";
                input2.LocationId = "L2500";
                input2.locationinfo = "Test Location 2";
                LocationInput[] array1 = { input1, input2 };
                LocationOutput output1 = new LocationOutput();
                output1 = locService.createLocationws(array1);
                String error1 = output1.errorMessage;
            catch (Exception e)


Best Answer chosen by Admin (Salesforce Developers) 

Take out the line that resets the URL, that's only needed for the enterprise or partner APIs.

All Answers


Take out the line that resets the URL, that's only needed for the enterprise or partner APIs.

This was selected as the best answer
dotnet developedotnet develope



i would like to suggest you tried with simple webservice which will return boolean/string.

if thats works for you then comment the code in the  createLocationws() method and print the parameters.


thats all i suggests you.




Thanks Simon, removing the reset URL Code worked. I never thought about it. Yeah, the endpoint is getting reset all the time bcoz of that... 


Appreciate your solution...