Search code examples
c#asp.netvisual-studiovisual-studio-2017web-reference

I Got Error :"the type or namespace name 'namespace2' does not exist int the namespaces 'namespace1' " when i add a WebService


I have a website with address (non-real) : www.example.com. in this site, i have a service (real) :http://www.example.com/services/smsService.asmx.

I have two asp.net projects in visual-studio-2017 : project1 and project2.

in project1 when i add a webreference(Add Service Reference... >Advanced...>Add Web Reference...) like http://www.example.com/services/smsService.asmx every thing is OK but in project2 the namespace of webReference doesn't recognize.

in project1 i use using NameSpace1.SmsWebService; and it works, but in project2 i get that error!

both projects are almost the same


Solution

  • After some googling and stack overflowing i found that i can add the service in other way.
    i used to add the service in this way:
    rightClick on Project > Add > Service Reference... > Advanced... > Add Web Reference... and then i write URL and ...
    in this way, some files like *.datasource couldn't downloaded (i don't know why!) and thus the project failed to build.
    I changed my way of add service with this:
    rightClick on Project > Add > Service Reference... > and then i filled the Address and clicked GO Button!
    Surprisingly everything was fine! except some classNames need a SoapClient at the end. means oldClass changed to oldClassSoapClient in my code!
    At last, this service appeared in Service References of solution, not Web References
    Thank you all buddies