burak Posted June 25, 2003 Posted June 25, 2003 Hello, I took the following pages as example for my soap application. http://docs.aspng.com/quickstart/aspplus/doc/webservicesintro.aspx http://docs.aspng.com/quickstart/aspplus/doc/servicesanddata.aspx I am trying to build a simple temperature converter. After following those examples, I ended upwith a CTemp.cs file. I included this file into my visual studio .net project and clicked Build Solution. I then ran this page <%@ Page Language="vb" AutoEventWireup="false" Codebehind="ctemp.aspx.vb" %> <%@ import Namespace="CTemp" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <title>ctemp</title> <script runat="server"> Dim convTemp As New CTemp() Dim sReturn As Decimal = convTemp.GetTem(32,"F", "C") Response.Write "Temp = " & sReturn </script> .... </body> It came back with Compilation Error Compiler Error Message: BC30182: Type expected. Source Error: Line 11: <script runat="server"> Line 12: /* Line 13: Dim convTemp As New CTemp()*/ (in red) Line 14: Dim sReturn As Decimal = convTemp.GetTemp(32,"F", "C") Do I need to compile the .cs file in a special way? How do I inclued this .cs file into my bv.net project? Thank you, Burak Quote
JABE Posted June 25, 2003 Posted June 25, 2003 You have to add a reference to the compiled DLL in your VB.NET project; you can do this via the Add Reference dialog. Quote
burak Posted June 25, 2003 Author Posted June 25, 2003 Thank you Jabe, How do I compile this .cs file? Quote
JABE Posted June 25, 2003 Posted June 25, 2003 Oh, I thought you already have this file compiled. > I included this file into my visual studio .net project and clicked Build Solution. So you actually included the .cs file into your VB.NET project. Well, that's not possible. You can do the ff: Re-code the .cs file to its equivalent .vb file. That way you don't have to compile the .cs file separately. OR Create your Web service project in C# and include the .cs file. Again, won't require you to compile separately OR Create a C# class library project. Include the .cs file into that project, then build. Its output will be a DLL. In the VB.NET project, add a reference to the compiled DLL via the Add Reference dialog. You should be able to access the C# class after doing these. Quote
burak Posted June 25, 2003 Author Posted June 25, 2003 Hi, I created a cs class project, then compiled it , and then tried to register it using regsvr32 "C:\Documents and Settings\GunayB\My Documents\Visual Studio Projects\ClassLibrary1\bin\Debug\ClassLibrary1.dll" I got a message saying "C:\Documents and Settings\GunayB\My Documents\Visual Studio Projects\ClassLibrary1\bin\Debug\ClassLibrary1.dll" was loaded, but the DllRegisterServer entry was not found. DllRegisterServer may not be exported, or a corrupt version of C:\Documents and Settings\GunayB\My Documents\Visual Studio Projects\ClassLibrary1\bin\Debug\ClassLibrary1.dll may be in memory. Consider using PView to detect and remove it." What do I do now? Quote
Administrators PlausiblyDamp Posted June 25, 2003 Administrators Posted June 25, 2003 .Net dlls don't need to be registered, registering components is just a COM thing. In your Visual Studio VB project right click on references in the solution explorer and browse to the dll from there. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
JABE Posted June 25, 2003 Posted June 25, 2003 Nope, don't register the DLL using REGSVR32; forget COM for now :) Just build the cs project, then add reference to the DLL in your VB.NET project. Quote
burak Posted June 25, 2003 Author Posted June 25, 2003 Thank you both. I added the dll to my project, compiled the solution and tried my page. I got the following error Compilation Error Compiler Error Message: BC30554: 'CTemp' is ambiguous. Source Error: Line 31: <System.Runtime.CompilerServices.CompilerGlobalScopeAttribute()> _ Line 32: Public Class Global_asax /* Line 33: Inherits CTemp.Global */ /* problem line*/ Line 34: Line 35: Private Shared __initialized As Boolean = false Is this because, CTemp.asmx also defines the CTemp class? Are we suppose to call this dll from a completely separate project? Quote
JABE Posted June 25, 2003 Posted June 25, 2003 In this case, try fully qualifying CTemp with its root namespace. By default, the root namespace has the same name as your project (minus the .proj extension). In the cs class lib project, you can inspect the root namespace via the Project Properties dialog. You should see a labeled textbox Root Namespace. Prepend this value to CTemp class whenever you use it. Quote
burak Posted June 25, 2003 Author Posted June 25, 2003 There is a "Project Folder" description, but I did not see any Root Namespace description. C:\Documents and Settings\GunayB\My Documents\Visual Studio Projects\ClassLibrary1 is the Project Folder description. Do I say Dim convTemp As New C:\Documents and Settings\GunayB\My Documents\Visual Studio Projects\ClassLibrary1/CTemp ? Quote
Administrators PlausiblyDamp Posted June 25, 2003 Administrators Posted June 25, 2003 (edited) VB has the rootnamespace option, in C# just open the .cs file containing the class and near the top it will say something like namespace project1 { Edited August 30, 2005 by PlausiblyDamp Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
burak Posted June 25, 2003 Author Posted June 25, 2003 This is my CTemp.asmx file ----------------------- Imports System.Web.Services <WebService(Namespace:="http://localhost/burak/ctemp/")> _ Public Class CTemp Inherits System.Web.Services.WebService <WebMethod()> Public Function GetTemp(ByVal Temperature As Decimal, _ ByVal FromUnits As String, _ ByVal ToUnits As String) As Decimal Select Case FromUnits.ToUpper.Chars(0) Case "F" ' Fahrenheit Select Case ToUnits.ToUpper.Chars(0) Case "F" ' No conversion necessary Return Temperature Case "C" ' Convert Fahrenheit to Celsius Return ((Temperature - 32) * 5) / 9 End Select Case "C" ' Celsius Select Case ToUnits.ToUpper.Chars(0) Case "C" 'No conversion necessary Return Temperature Case "F" ' Convert Celsius to Fahrenheit Return ((Temperature * 9) / 5) + 32 End Select End Select End Function .... End Class ----------------- I ran the wsdl command as wsdl.exe /l:'VB' http://172.16.0.124/burak/ctemp/ctemp.asmx?wsdl an ended up with CTemp.vb I then added this CTemp.vb class into my vb.net project and tried to compile but it said the namespaces were different. I looked into the vb class and its namespace was tempuri.org even though I had set it to my own server address in the .asmx file. So I went in and change the namespaces in the vb class to y own server and tried to compile, it still did not work. It's very frustrating. Any ideas? Quote
scrambones Posted October 3, 2003 Posted October 3, 2003 you should just add a web reference to your web service. If you add a web reference it will default to localhost as the name. Add a variable that references the web service object. C# - private localhost.MyService ws = new localhost.MyService(); This will add the web service reference and all the public web methods are exposed. Just call them. There are 2 ways to call these methods Sync and Async. C# will build them for you. Sync method = int AddNumbers = ws.GetTotal(1,1) where GetTotal adds the two numbers 1 and 1 and returns 2. If GetTotal returns a int Async method = IAsyncResult ar1 = ws.BeginGetTotal(1,1,null,null); WaitHandle[] wh = {ar1.AsyncWaitHandle}; WaitHandle.WaitAll(wh); AddNumbers = ws.EndGetTotal(ar1); Use this method if it is a long process of in an Multithread app Also do not name your namespace the actual address ex: [WebService(Namespace="TotalNumbers", Name="MY Number Adding Service", Description="<b>This service will add numbers together" I hope this will help. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.