如何在Xamarin.Forms(.NET Standard 2.0)项目中添加ASMX Web服务?
Hey there! I totally get how frustrating it is when you can't find that expected "Add Web Reference" option in Visual Studio 2017 for your Xamarin.Forms (.NET Standard 2.0) project. Let me walk you through a couple of reliable ways to get your ASMX Web service set up.
The old-school "Add Web Reference" option isn't front-and-center for .NET Standard projects in VS2017, but it's hiding in the advanced settings of the Service Reference dialog:
- Right-click your .NET Standard 2.0 project in Solution Explorer, then select Add > Service Reference
- In the Service Reference window that pops up, click the Advanced button at the bottom-left corner
- Now in the Service Reference Settings window, you'll see the Add Web Reference button at the bottom-left—this is exactly what you're looking for!
- Enter your ASMX service's URL (e.g.,
http://your-service-domain/YourService.asmx), give the reference a friendly namespace name, and click Add Reference to finish.
If the first method doesn't work for some reason, you can generate the service proxy class manually using the .NET Framework's SvcUtil tool:
- Open the Developer Command Prompt for Visual Studio 2017 (you can find this in the Visual Studio folder under your Start Menu)
- Run this command, replacing the placeholders with your service details:
svcutil.exe http://your-service-url/YourService.asmx /out:ServiceProxy.cs /namespace:YourApp.Services - Once the command finishes, add the generated
ServiceProxy.csfile to your .NET Standard project - Don't forget to add a reference to the
System.Web.Servicesassembly: Right-click your project > Add > Reference > Go to the Assemblies tab > Locate and checkSystem.Web.Services
Quick Note
After setting up the reference, you can use the service just like any other class in your project. For example:
var serviceClient = new YourApp.Services.YourService(); var response = serviceClient.YourServiceMethod();
Also, make sure your ASMX service allows cross-origin requests (CORS) if your Xamarin.Forms app is running on a simulator or physical device—otherwise you'll run into access errors.
内容的提问来源于stack exchange,提问作者Ghizlane.S

